Level 1 · Entry Foundations¶
Goal: build a small but complete JSON API with FastAPI, and be able to say exactly what happens to a request between the socket and your function — and back.
Three ideas carry you through all ten modules:
- The signature is the specification. Type hints and markers like
Query(),Body()andForm()decide where data comes from, how it's converted, what's rejected, and what the docs say. Change the signature and you've changed the API. - Validate at the edge, trust inside. Pydantic checks everything before your code runs, and response models check everything before it leaves. Your endpoint body can assume clean data.
- Keep endpoints thin. Parse, call ordinary Python code, return. Business rules live in modules that don't import FastAPI, which makes them easy to test and easy to move to a database in Level 2.
Modules¶
- What FastAPI Is: ASGI, Starlette, Pydantic and One Request — the layers, a raw ASGI app, what happens at import time vs request time
- Installing FastAPI & Your First App —
fastapi[standard],fastapi devvsfastapi run, the generated docs - Path & Query Parameters —
Annotated, constraints, enums, lists, query models and the route-order trap - Request Bodies with Pydantic Models — nested models, every-error-at-once validation,
PATCHwithexclude_unset, content types - Response Models & Status Codes — filtering secrets, return annotations, 201/204,
ResponseValidationError - Pydantic v2 in Depth — reusable
Annotatedtypes, validators, aliases, strict mode, serialization - Errors: HTTPException, Validation Errors & Handlers — domain exceptions, custom 404/405/422 shapes, crashes
- Forms, File Uploads, Headers & Cookies —
Form(),UploadFile, size and type checks, cookie flags - APIRouter & Project Structure — routers, prefixes, tags, a layout that avoids circular imports
- Project — An In-Memory Notes API — CRUD, search, pagination, error handling and a pytest suite
What you need before starting¶
- Python fundamentals: functions, classes, type hints, modules, virtual
environments. FastAPI leans on type hints more than any other framework; if
list[str] | Nonelooks unfamiliar, work through Python Mastery Path first. - HTTP basics: methods, status codes, headers, JSON. The REST API Mastery Path covers API design in depth; this course focuses on implementing it in FastAPI.
- Python 3.10 or newer (the
X | Nonesyntax needs it). The examples were run on 3.14. curlor any HTTP client. Every endpoint can also be exercised from/docs.
How the examples were checked¶
Every code sample in this level was run with FastAPI 0.143.0, Pydantic 2.14.0,
Starlette 1.7.0 and Uvicorn 0.54.0 on Python 3.14.7, mostly through FastAPI's
TestClient and, where server behaviour matters (startup output, logs, headers), under a
real Uvicorn process with curl. Outputs are copied from those runs, sometimes trimmed
or re-wrapped for width, and marked when they are. Timestamps and process IDs will differ
on your machine.
About versions
FastAPI is still numbered 0.x and releases frequently, so small details change. The
concepts in this level — how parameters are sourced, how Pydantic validates, how
response models filter — have been stable for years. Where this level found
something version-specific (the test client's httpx2 deprecation warning, the
stricter Content-Type handling for JSON bodies, how include_router stores routes),
the lesson says so. Run pip list | grep -i fastapi to see what you have.