mirror of
https://github.com/fastapi/fastapi.git
synced 2026-03-30 12:43:15 -04:00
✨ Add support for Pydantic models for parameters using Query, Cookie, Header (#12199)
This commit is contained in:
committed by
GitHub
parent
0903da78c9
commit
55035f440b
21
docs_src/header_param_models/tutorial002.py
Normal file
21
docs_src/header_param_models/tutorial002.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from typing import List, Union
|
||||
|
||||
from fastapi import FastAPI, Header
|
||||
from pydantic import BaseModel
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
class CommonHeaders(BaseModel):
|
||||
model_config = {"extra": "forbid"}
|
||||
|
||||
host: str
|
||||
save_data: bool
|
||||
if_modified_since: Union[str, None] = None
|
||||
traceparent: Union[str, None] = None
|
||||
x_tag: List[str] = []
|
||||
|
||||
|
||||
@app.get("/items/")
|
||||
async def read_items(headers: CommonHeaders = Header()):
|
||||
return headers
|
||||
Reference in New Issue
Block a user