- FastAPI – One Error Shape for the Whole API
Every failure leaving as the same JSON body, so a client needs one error parser. Custom exception classes raised from the service layer, handlers that turn them into responses, and flattening pydantic's nested validation errors into field messages a form can render. Plus the trap that cost this project a real bug: a handler registered for bare Exception does NOT run where the others do.
- FastAPI – Designing the REST API
Turning endpoints into an API someone else can use. Resource naming, PATCH versus PUT, response_model and what it hides, and giving a state change its own endpoint instead of making it a writable field. Then pagination done properly — a generic Page[T] envelope, bounded page sizes, and the ORDER BY that stops page two repeating rows from page one.
- FastAPI – SQLAlchemy, Sessions and Migrations
A real data layer. The engine and one session per request, typed SQLAlchemy 2.0 models, the repository pattern, and who owns the transaction. Then Alembic: naming constraints so a downgrade can refer to them, and never editing an applied migration. Includes the N+1 problem, eager loading, and why expire_on_commit=False matters specifically in FastAPI.
- FastAPI – Dependency Injection in Practice
The feature FastAPI is built on. Depends(), dependencies that yield so setup and teardown live together, sub-dependencies, and collapsing the whole thing into one readable Annotated alias so a route signature states its own security rules. Then dependency_overrides, which is what makes any of it testable — and the reason an override keyed on the wrong function object silently does nothing.
- FastAPI – Project Structure That Survives Growth
The question the official docs answer least well. How a single main.py becomes routes, services, repositories, schemas and models — what belongs in each layer, and the rules that keep them apart: routes own HTTP, services own the rules, and repositories never commit because only the caller knows where a transaction ends. Plus typed settings read once, so a misspelt variable is a startup error.