Debian Codegraph @

docs_src/response_model/tutorial001_py310.py

raw
1 from typing import Any
2
3 from fastapi import FastAPI
4 from pydantic import BaseModel
5
6 app = FastAPI()
7
8
9 class Item(BaseModel):
10 name: str
11 description: str | None = None
12 price: float
13 tax: float | None = None
14 tags: list[str] = []
15
16
17 @app.post("/items/", response_model=Item)
18 async def create_item(item: Item) -> Any:
19 return item
20
21
22 @app.get("/items/", response_model=list[Item])
23 async def read_items() -> Any:
24 return [
25 {"name": "Portal Gun", "price": 42.0},
26 {"name": "Plumbus", "price": 32.0},
27 ]