UNKNOWN
Project description
aiohttp_route_decorator
The library provides @route decorator for aiohttp.web, resembling the contract of Flask @app.route.
The imaginary aiohttp @app.route decorator is discouraged for multiple reasons; this one tries to solve part of those problems (the app doesn’t need to be global at the very least).
Installation
pip install aiohttp_session_decorator
Usage
Create a route object in each of your handler modules, and decorate the handlers:
from aiohttp_route_decorator import RouteCollector
route = RouteCollector()
@route('/')
async def handler(request):
return web.Response(body=b'OK')
@route('/login/', methods=['GET', 'POST'], name='login')
async def handler(request):
if request.method == 'POST':
return web.Response(body=b'OK')
return web.Response(body=b'Login')
When you init the application, push the collected routes into app.router:
from aiohttp import web
from myapp import handlers
def run():
app = web.Application()
handlers.route.add_to_router(app.router)
web.run_app(app)
Parameters reference
route(path, *, method='GET', methods=None, name=None, **kwargs)
path (str) — route path. Should be started with slash ('/').
method (str) — HTTP method for route. Should be one of 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS' or '*' for any method.
methods (List[str]) — optional shortcut for creating several routes with different HTTP methods at once. If used, should be a list of acceptable values for method argument.
name (str) — optional route name.
kwargs — other parameters to be passed to aiohttp.web.Resource.add_route().
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
Hashes for aiohttp_route_decorator-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46519f2638d05be9649084a00096274b2563c66c7ea90ebdcf487ac636131dbc |
|
MD5 | e8cfd68e148c5d3de48e70c35de8d66c |
|
BLAKE2b-256 | 1533470f66a468b2baaeec1c7cb802402c15845d3b3bfba7aed9da95d3fa3d8c |