docs_src/dependencies/tutorial001_02_an_py310.py
raw| 1 | from typing import Annotated |
| 2 | |
| 3 | from fastapi import Depends, FastAPI |
| 4 | |
| 5 | app = FastAPI() |
| 6 | |
| 7 | |
| 8 | async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100): |
| 9 | return {"q": q, "skip": skip, "limit": limit} |
| 10 | |
| 11 | |
| 12 | CommonsDep = Annotated[dict, Depends(common_parameters)] |
| 13 | |
| 14 | |
| 15 | @app.get("/items/") |
| 16 | async def read_items(commons: CommonsDep): |
| 17 | return commons |
| 18 | |
| 19 | |
| 20 | @app.get("/users/") |
| 21 | async def read_users(commons: CommonsDep): |
| 22 | return commons |