docs_src/query_params/tutorial004_py310.py
raw| 1 | from fastapi import FastAPI |
| 2 | |
| 3 | app = FastAPI() |
| 4 | |
| 5 | |
| 6 | @app.get("/users/{user_id}/items/{item_id}") |
| 7 | async def read_user_item( |
| 8 | user_id: int, item_id: str, q: str | None = None, short: bool = False |
| 9 | ): |
| 10 | item = {"item_id": item_id, "owner_id": user_id} |
| 11 | if q: |
| 12 | item.update({"q": q}) |
| 13 | if not short: |
| 14 | item.update( |
| 15 | {"description": "This is an amazing item that has a long description"} |
| 16 | ) |
| 17 | return item |