Сохрани себе шаблон для быстрого старта HTTP API на FastAPI с базовой валидацией данных. Используй Pydantic для определения схемы данных и автоматической генерации документации.
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
is_offer: bool = None
@app.post("/items/", response_model=Item)
async def create_item(item: Item):
return item
@app.get("/")
async def read_root():
return {"message": "Welcome to the FastAPI!"}