This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage 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_route_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 index(request):
        return web.Response(body=b'OK')

@route('/publish', method='POST')
async def publish(request):
        return web.Response(body=b'OK')

@route('/login', methods=['GET', 'POST'], name='login')
async def login(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)

Non-decorator use

If you prefer to keep your routes together, you can construct the list manually after your handers:

from aiohttp_route_decorator import RouteCollector, Route

async def index(request):
        return web.Response(body=b'OK')

async def publish(request):
        return web.Response(body=b'OK')

async def login(request):
        if request.method == 'POST':
                return web.Response(body=b'OK')
        return web.Response(body=b'Login')

routes = RouteCollector([
        Route('/', index),
        Route('/publish', publish, method='POST'),
        Route('/login', login, methods=['GET', 'POST'], name='login'),
])

Prefixed routes

You can provide common route prefix that will be prepended to all routes:

from aiohttp_route_decorator import RouteCollector

routes = RouteCollector(prefix='/app')

@route('/')
async def index(request):
        return web.Response(body=b'OK')

@route('/publish', method='POST')
async def publish(request):
        return web.Response(body=b'OK')

...

handlers.route.add_to_router(app.router)
# /app/ -> index
# /app/publish -> publish

You can also provide the prefix within add_to_router() call instead:

from aiohttp_route_decorator import RouteCollector

routes = RouteCollector()

@route('/')
async def index(request):
        return web.Response(body=b'OK')

@route('/publish', method='POST')
async def publish(request):
        return web.Response(body=b'OK')

...

handlers.route.add_to_router(app.router, prefix='/app')
# /app/ -> index
# /app/publish -> publish

…or use both:

from aiohttp_route_decorator import RouteCollector

routes = RouteCollector(prefix='/app')

@route('/')
async def index(request):
        return web.Response(body=b'OK')

@route('/publish', method='POST')
async def publish(request):
        return web.Response(body=b'OK')

...

handlers.route.add_to_router(app.router, prefix='/project')
# /project/app/ -> index
# /project/app/publish -> publish

The non-decorator version of RouteCollector can also accept prefix:

from aiohttp_route_decorator import RouteCollector, Route

async def index(request):
        return web.Response(body=b'OK')

async def publish(request):
        return web.Response(body=b'OK')

routes = RouteCollector(prefix='/app', routes=[
        Route('/', index),
        Route('/publish', publish, method='POST'),
])

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().
Release History

Release History

0.1.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
aiohttp_route_decorator-0.1.3.tar.gz (3.1 kB) Copy SHA256 Checksum SHA256 Source Jun 25, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting