Path + Query + Request body - FastAPI

PHOTO EMBED

Wed Apr 20 2022 02:10:26 GMT+0000 (Coordinated Universal Time)

Saved by @newaaa41 ##fastapi ##python ##post_request

from fastapi import FastAPI

app = FastAPI()


@app.get("/items/")

async def read_items(q: str | None = None):

    results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
    if q:
        results.update({"q": q})
    return results
content_copyCOPY

https://fastapi.tiangolo.com/tutorial/query-params-str-validations/