mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-29 16:31:15 -05:00
✨Add support for PEP-593 Annotated for specifying dependencies and parameters (#4871)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
15
docs_src/annotated/tutorial003.py
Normal file
15
docs_src/annotated/tutorial003.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from fastapi import FastAPI, Path
|
||||
from fastapi.param_functions import Query
|
||||
from typing_extensions import Annotated
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
async def read_items(item_id: Annotated[int, Path(gt=0)]):
|
||||
return {"item_id": item_id}
|
||||
|
||||
|
||||
@app.get("/users")
|
||||
async def read_users(user_id: Annotated[str, Query(min_length=1)] = "me"):
|
||||
return {"user_id": user_id}
|
||||
Reference in New Issue
Block a user