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