docs_src/extra_models/tutorial004_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 |
| 10 | |
| 11 | |
| 12 | items = [ |
| 13 | {"name": "Foo", "description": "There comes my hero"}, |
| 14 | {"name": "Red", "description": "It's my aeroplane"}, |
| 15 | ] |
| 16 | |
| 17 | |
| 18 | @app.get("/items/", response_model=list[Item]) |
| 19 | async def read_items(): |
| 20 | return items |