-
Notifications
You must be signed in to change notification settings - Fork 581
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
add route decorators #26
base: master
Are you sure you want to change the base?
Conversation
Usage example: from japronto import Application
app = Application()
@app.get('/')
def hello(request):
return request.Response(text='Hello world!')
app.run(debug=True) |
Oh, it looks like you're not ready to implement this :) Didn't read the whole thread... feel free to close. |
@r0fls we can keep it open and maybe modify it as and when @squeaky-pl revamps the routing? |
Yes, I would like to keep it open, if it takes too much time to revamp routing I am gonna covert it into a recipe. |
What's the progress on this? |
@squeaky-pl @r0fls Any update about this feature? This is the most "pythonic" and practic way to do routing, like Flask or Sanic. |
Any update? |
Any update ? @squeaky-pl |
Looks great, add this # import
from inspect import iscoroutinefunction
####
def route(self, path: str = '/', methods: list = []):
'''
Shorthand route decorator. Avoids need to register
handlers to the router directly with `app.router.add_route()`.
'''
def decorator(handler):
async def wrapper(*args, **kwargs):
# check awaitable handler
if iscoroutinefunction(handler):
return await handler(*args, **kwargs)
return handler(*args, **kwargs)
self.router.add_route(path, wrapper, methods=methods)
return wrapper
return decorator |
Addresses issue #5