mirror of
https://github.com/Fishwaldo/huma.git
synced 2025-07-07 21:38:21 +00:00
21 lines
524 B
Python
21 lines
524 B
Python
from fastapi import FastAPI, Header, Depends, Response
|
|
from pydantic import BaseModel
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Item(BaseModel):
|
|
id: int
|
|
name: str
|
|
price: float
|
|
is_offer: bool = False
|
|
|
|
|
|
def processed_header(authorization: str = Header("")) -> str:
|
|
return authorization.split(" ").pop(0)
|
|
|
|
|
|
@app.get("/items/{id}")
|
|
def read_root(id: int, response: Response, *, auth: str = Depends(processed_header)):
|
|
response.headers["x-authinfo"] = auth
|
|
return Item(id=id, name="Hello", price=1.25, is_offer=False)
|