Skip to course content
Free FastAPI backend course

FastAPI for AI Backend Development

Module 07 Activity

Scenario

Move shared request-time concerns into dependencies without pulling logic in with them.

What you build

Dependencies for settings, clients, authentication and sessions - overridable in tests, with business logic left in services.

Steps

  1. Convert repeated checks at the top of handlers into dependencies, and confirm they appear in the generated documentation.
  2. Put expensive objects behind a cached dependency and prove they are built once across several requests.
  3. Use route-level dependencies for checks that guard rather than supply.
  4. Override one dependency in a test and confirm the whole request path still runs.
  5. Audit your dependencies for business logic and move any you find into services.
  6. Check no dependency chain is more than two or three deep.

Evidence to hand in

Review checklist