Building APIs with FastAPI
Create a REST API with FastAPI including path params, request bodies, and automatic docs.
FastAPI combines speed with developer ergonomics.
A minimal API
from fastapi import FastAPI
app = FastAPI()
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str | None = None):
return {"item_id": item_id, "q": q}What you get for free
- Automatic interactive docs at
/docs. - Type-checked request parameters.
- Async-ready with
async def.
Run it with uvicorn main:app --reload and visit /docs to try it live.
AdSense — in-article slot