Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to aiohttp.web #5

Closed
playpauseandstop opened this issue Jul 1, 2015 · 4 comments
Closed

Enhancements to aiohttp.web #5

playpauseandstop opened this issue Jul 1, 2015 · 4 comments
Labels
feat A new feature

Comments

@playpauseandstop
Copy link
Owner

There are several desired enhancements to aiohttp.web library that widely used in backend applications which should be added to rororo,

  • Improved Application to support debug mode and proper logging while serving with gunicorn
  • add_route context manager
  • Handling single static files, not directories
  • Error handling middleware
@playpauseandstop
Copy link
Owner Author

add_route context manager example,

from rororo.aio.routes import add_route_context

from . import api as api_views


app = Application(...)

with add_route_context(app, api_views, '/api', 'api') as add_route:
    add_route('GET', '/', 'index')
    add_route('POST', '/posts', 'add_post')
    add_route('GET', '/posts', 'list_posts')

This should create 3 route handlers,

GET /api/ -> api.index
POST /api/posts -> api.add_post
GET /api/posts -> api.list_posts

@playpauseandstop
Copy link
Owner Author

add_static context manager example,

from pathlib import Path

from rororo.aio.routes import add_static_context


rel = Path(__file__).dirname

app = Application(...)

static_dir = rel / '..' / 'static'
with add_static_context(app, static_dir) as add_static:
    add_static('/favicon.ico', 'images/favicon.ico')
    add_static('/static')

This should create 2 static route handlers,

GET /favicon.ico -> ../static/images/favicon.ico
GET /static/{filename} -> ../static/{filename}

@playpauseandstop playpauseandstop added the feat A new feature label Sep 22, 2015
@sloria
Copy link

sloria commented Oct 25, 2015

Greetings!

I hope you don't mind, but I adapted your add_route_context helper in a utilities package I just published: aiohttp_utils.

I made a few changes to make the following possible:

  1. Passing handlers rather than strings to add_route
  2. Passing both module names and handler names as strings.

See the examples here: https://aiohttp-utils.readthedocs.org/en/latest/modules/routing.html#aiohttp_utils.routing.add_route_context

I'd be glad to contribute them to rororo if you'd like.

@playpauseandstop
Copy link
Owner Author

@sloria

Greetings! Great to hear about aiohttp_utils, closing this ticket in favor of,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat A new feature
Projects
None yet
Development

No branches or pull requests

2 participants