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'

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.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.0b2.zip (11.1 kB view details)

Uploaded Source

File details

Details for the file WebDispatch-1.0b2.zip.

File metadata

  • Download URL: WebDispatch-1.0b2.zip
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for WebDispatch-1.0b2.zip
Algorithm Hash digest
SHA256 5bd9dc7deff779e75a8f14d9556d165f1e4b74dd3eb6ef871d5f6741bee8f9c5
MD5 92c5658cdbb62f3398329a2d0374073c
BLAKE2b-256 b5b687817e023bd416599a03a0ec95a743462e3fdd241290650488089bb91f92

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