Python: FastAPI: Add support for api_route

Note that `route` did not actually work (that also comes from the
underlying web framework library Starlette)
This commit is contained in:
Rasmus Wriedt Larsen
2021-09-12 15:59:08 +02:00
parent 3661ff3bd8
commit b1f8b5352b
2 changed files with 12 additions and 5 deletions

View File

@@ -52,8 +52,9 @@ async def create_item(item: Item): # $ requestHandler routedParameter=item
async def create_item2(item1: Item, item2: Item): # $ requestHandler routedParameter=item1 routedParameter=item2
return (item1, item2) # $ HttpResponse
@app.api_route("/baz/{baz_id}", methods=["GET"]) # $ routeSetup="/baz/{baz_id}"
async def get_baz(baz_id: int): # $ requestHandler routedParameter=baz_id
return {"baz_id2": baz_id} # $ HttpResponse
# Docs:
# see https://fastapi.tiangolo.com/tutorial/path-params/
@@ -69,5 +70,3 @@ async def create_item2(item1: Item, item2: Item): # $ requestHandler routedParam
#
# - https://fastapi.tiangolo.com/tutorial/middleware/
# - https://fastapi.tiangolo.com/tutorial/encoder/
#
# - `app.route()`