Open
Conversation
Contributor
Author
|
Usage example: from japronto import Application
app = Application()
@app.get('/')
def hello(request):
return request.Response(text='Hello world!')
app.run(debug=True) |
Contributor
Author
|
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? |
Owner
|
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. |
Contributor
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses issue #5