FastAPI, by Calling It

Routes, validation and documentation that come from the same annotations - each one runnable on the page.

26 modules Free, no login Updated 15 October 2026

About this track

FastAPI is a thin, well-chosen layer over two ideas you can learn separately: ASGI, which is what a Python web application actually is, and Pydantic, which turns your annotations into validation. Almost everything that looks like framework magic is one of those two doing its job.

This track works up from a first route to dependencies, middleware and testing. There is no server on these pages - a browser tab cannot listen on a port - so a test client calls the app the way a server would, which means routing, validation, status codes and the generated schema all behave exactly as they do in production.

Every example runs a real FastAPI application in the browser against a test client, so a request and its response are both on the page - including the requests that are rejected, which is where most of the framework's behaviour is visible.

What you will be able to do

How the track is ordered

The first endpoint comes first, then the request - path parameters, query parameters, bodies, headers, forms and files - because everything else assumes you can read the input. Responses and status codes follow. Dependencies get the largest share of the track, since they are the mechanism FastAPI is built around and the thing that makes an application testable. The track closes with structure, security, testing and the async question, which is where most production problems actually live.

Where this leads

FastAPI is Pydantic applied to HTTP, so the Pydantic track explains the validation layer these pages rely on. Beyond it lie deployment, databases and the operational material a running service needs.

All 26 modules, in teaching order

  1. 01What FastAPI IsSee what FastAPI actually is: a thin layer over Starlette and Pydantic. Learn the two ideas that explain almost every feature it offers.
  2. 02Your First EndpointWrite a GET handler, run the app, call the endpoint, and see how the decorator, the return value and the route ordering rule fit together.
  3. 03Path ParametersAdd a path parameter with a type annotation, send a request with a wrong type, and watch FastAPI extract, convert and validate in one step.
  4. 04Query ParametersAdd query parameters with defaults and type hints, send a request, and watch FastAPI validate and document them from a single annotation.
  5. 05Request BodiesDefine a Pydantic model and use it as a request body. One class gives you parsing, validation and OpenAPI documentation in a single declaration.
  6. 06Response ModelsSet a response_model on an endpoint, return a full ORM object, and watch FastAPI strip every field the model does not declare before sending.
  7. 07Reading a 422Read a 422 validation error field by field, trace it back to the Pydantic model, and reshape the response into something callers can use.
  8. 08HTTP Methods and RoutingMap GET, POST, PUT and DELETE to handler functions, follow the matching logic, and see what each HTTP method promises to the caller.
  9. 09Headers and CookiesRead a request header and a cookie inside a FastAPI endpoint, set a cookie on the response, and see what each transport is properly for.
  10. 10Form Data and File UploadsAccept form fields and file uploads in a FastAPI endpoint, inspect the multipart body, and see why form data is not JSON or a query string.
  11. 11Status CodesReturn the right HTTP status code for each outcome, compare it with 200-for-everything, and see the information the wrong choice discards.
  12. 12Error HandlingRaise an HTTPException, register a custom exception handler, and keep HTTP status codes out of the business logic that does the real work.
  13. 13APIRouterMove endpoints into an APIRouter, mount it with a prefix, and see how a growing FastAPI app stays organised without circular imports.
  14. 14Dependency InjectionDeclare what an endpoint needs with Depends, let FastAPI resolve and inject it, and see how testing and swapping implementations get simpler.
  15. 15Dependencies with yieldWrite a dependency that yields a database session, watch FastAPI run setup before the handler and teardown after it, then see the pattern.
  16. 16Sub-dependenciesChain dependencies that depend on other dependencies, follow the resolution order, and see FastAPI call each one correctly before your handler.
  17. 17Class DependenciesTurn a class with __init__ parameters into a FastAPI dependency and see how any callable with the right signature becomes injectable config.
  18. 18Router and Global DependenciesAttach a dependency to a router so every endpoint under it runs the same check, and spot the unprotected endpoint the pattern catches.
  19. 19Dependency OverridesSwap a real dependency for a test double with dependency_overrides, run the test, and see why the pattern makes FastAPI simple to test.
  20. 20async def or defCompare async def and plain def endpoints in FastAPI, see where each one runs, and spot the mistake that turns a fast framework into a slow one.
  21. 21Background TasksAdd a BackgroundTasks parameter, schedule work after the response leaves, and see the point where this runner needs replacing with a task queue.
  22. 22Lifespan EventsWrite a lifespan context manager that opens a connection pool at startup and closes it on shutdown, and see why per-request setup is wasteful.
  23. 23TestingWrite tests with TestClient, call endpoints without a running server, override dependencies for isolation, and see what good tests assert.
  24. 24OpenAPI and the DocsOpen the auto-generated Swagger UI, trace every field back to your type annotations, and see how much of an API's usability the schema decides.
  25. 25Security BasicsAdd OAuth2PasswordBearer as a dependency, extract and verify a token, and see how authentication fits into FastAPI's dependency injection.
  26. 26Project StructureOrganise a FastAPI project into routers, models and dependencies across files and see a layout that scales without causing circular imports.

Other tracks