Last active
April 25, 2021 18:13
-
-
Save daltonmatos/44301ec563ed914ad8fc8bb1d583e15b to your computer and use it in GitHub Desktop.
Asyncworker: Recebendo parametros do Path do Request através de typehints
This file contains 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
from aiohttp import web | |
from asyncworker import App | |
from asyncworker.http.types import PathParam | |
app = App() | |
@app.http.get(["/path/{_bool}/{string}/{number}/{_float}"]) | |
async def user_books(_bool: PathParam[bool], string: PathParam[str]): | |
return web.json_response( | |
{"bool": await _bool.unpack(), "string": await string.unpack()} | |
) | |
app.run() |
This file contains 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
from aiohttp import web | |
from asyncworker import App | |
from asyncworker.http.types import PathParam | |
app = App() | |
@app.http.get(["/path/{_bool}/{string}/{number}/{_float}"]) | |
async def user_books( | |
_bool: PathParam[bool], | |
string: PathParam[str], | |
number: PathParam[int], | |
_float: PathParam[float], | |
): | |
return web.json_response( | |
{ | |
"bool": await _bool.unpack(), | |
"string": await string.unpack(), | |
"number": await number.unpack(), | |
"_float": await _float.unpack(), | |
} | |
) | |
app.run() |
This file contains 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
from aiohttp import web | |
from asyncworker import App | |
from asyncworker.http.types import PathParam | |
app = App() | |
@app.http.get(["/users/{user_id}/books"]) | |
async def user_books(user_id: PathParam[int]): | |
return web.json_response({"user_id": await user_id.unpack()}) | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment