docs_src/path_params_numeric_validations/tutorial002_an_py310.py
raw| 1 | from typing import Annotated |
| 2 | |
| 3 | from fastapi import FastAPI, Path |
| 4 | |
| 5 | app = FastAPI() |
| 6 | |
| 7 | |
| 8 | @app.get("/items/{item_id}") |
| 9 | async def read_items( |
| 10 | q: str, item_id: Annotated[int, Path(title="The ID of the item to get")] |
| 11 | ): |
| 12 | results = {"item_id": item_id} |
| 13 | if q: |
| 14 | results.update({"q": q}) |
| 15 | return results |