Starter
Path parameters, an optional query parameter and a validated request body — the three things a type hint gets you for free.
# A real FastAPI app, running entirely in your browser.# Edit anything, press Run, then open /docs for the interactive API docs. from fastapi import FastAPIfrom pydantic import BaseModel, Field app = FastAPI(title="Playground") class Item(BaseModel): name: str price: float = Field(gt=0) tags: list[str] = [] @app.get("/")async def root(): return {"message": "It works. Try /items/42?q=hello"} @app.get("/items/{item_id}")async def read_item(item_id: int, q: str | None = None): return {"item_id": item_id, "q": q} @app.post("/items")async def create_item(item: Item): return {"created": item.name, "with_tax": round(item.price * 1.23, 2)}