Debian Codegraph @

docs_src/path_operation_configuration/tutorial002_py310.py

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