Skip to main content

dispatch request on wsgi application.

Project description

WebDispatch

WebDispatch is dispatcher collection for wsgi application. That has no dependency to exsiting frameworks, but works fine with WebOb.

Dispatch and Generate URL

dispatch with url patterns.

example helo application:

>>> from webob.dec import wsgify
>>> @wsgify
... def greeting(request):
...     return "Hello, %s" % request.urlvars['name']

create and configure URL Dispatcher:

>>> from webdispatch import URLDispatcher
>>> dispatcher = URLDispatcher()
>>> dispatcher.add_url('top', '/hello/{name}', greeting)

invoke dispatcher as WSGI Application:

>>> from webob import Request
>>> req = Request.blank('/hello/webdispatch')
>>> res = req.get_response(dispatcher)
>>> res.body
'Hello, webdispatch'

Wildcard

You can use wildcard after last slash. Pattern with wildcard consumes paths before the wildcard, (and make that new script_name,) and remained paths becomes new path_info.

>>> @wsgify
... def with_pathinfo(request):
...     return "Hello, %s" % request.path_info
>>> dispatcher.add_url('top', '/with_pathinfo/*', with_pathinfo)
>>> req = Request.blank('/with_pathinfo/this/is/pathinfo')
>>> res = req.get_response(dispatcher)
>>> res.body
'Hello, this/is/pathinfo'

Action Dispatch

ActionDispatcher invokes object method with action name from urlvars.

action handler class:

>>> class MyHandler(object):
...     @wsgify
...     def greeting(self, request):
...         return "Hello"

create and configure ActionDispatcher:

>>> from webdispatch import ActionDispatcher
>>> actiondispatcher = ActionDispatcher()
>>> actiondispatcher.register_actionhandler(MyHandler)

add action url with urlvars named action:

>>> dispatcher.add_url('action_dispatch', '/actions/{action}', actiondispatcher)

invoke wsgi appclication.:

>>> req = Request.blank('/actions/greeting')
>>> res = req.get_response(dispatcher)
>>> res.body
'Hello'

Method Dispatch

dispatch by HTTP METHOD restfully.

sample wsgi app:

>>> @wsgify
... def get_hello(request):
...    return "Get Hello"
>>> @wsgify
... def post_hello(request):
...    return "Post Hello"

create and configure:

>>> from webdispatch import MethodDispatcher
>>> restapp = MethodDispatcher()
>>> restapp.register_app('get', get_hello)
>>> restapp.register_app('post', post_hello)

Each applications are registered with HTTP Method name.

invoke WSGI application:

>>> req = Request.blank('/')
>>> res = req.get_response(restapp)
>>> res.body
'Get Hello'

Changes

1.0.1

  • include char of “-” to urlmatch words #9

1.0

  • no changes

1.0b4

  • fix response body to bytes

1.0b3

  • fix some bugs

1.0b2

  • fix setup bug

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

WebDispatch-1.0.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

WebDispatch-1.0.1-py2.py3-none-any.whl (12.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file WebDispatch-1.0.1.tar.gz.

File metadata

  • Download URL: WebDispatch-1.0.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for WebDispatch-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9e0d3d8bd4ab272956bcf6c15695e134e9638a9562125816407cd80ba7b36805
MD5 418ec3bf64a57cf20d8d6ea61787037a
BLAKE2b-256 1c8ad24add6c0276e2c3f052ae6c4c2da143b2490ebd00215b72b471730e3b37

See more details on using hashes here.

File details

Details for the file WebDispatch-1.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for WebDispatch-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fa9c7cec96ea79758ca3e029a6a9d22b8885e033c4dd93b10f5b7fdd3c733aaa
MD5 f34703e67878bc45df27a877853fc076
BLAKE2b-256 ab5b4046d28527aafc95606aca7e5661ba6e97252fa78ed546a79119a40b8841

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page