Skip to content

Instantly share code, notes, and snippets.

@daltonmatos
Last active April 25, 2021 18:13
Show Gist options
  • Save daltonmatos/44301ec563ed914ad8fc8bb1d583e15b to your computer and use it in GitHub Desktop.
Save daltonmatos/44301ec563ed914ad8fc8bb1d583e15b to your computer and use it in GitHub Desktop.
Asyncworker: Recebendo parametros do Path do Request através de typehints
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()
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()
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