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