fastapi-master/docs_src/extra_models/tutorial004.py

23 lines
381 B
Python
Raw Normal View History

2024-08-24 12:41:47 +08:00
from typing import List
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: str
items = [
{"name": "Foo", "description": "There comes my hero"},
{"name": "Red", "description": "It's my aeroplane"},
]
@app.get("/items/", response_model=List[Item])
async def read_items():
return items