Skip to content

9. Task API & Querying Features

The Task model exists, the database has a tasks table, we can't access them via our API yet.

This chapter builds the task API and introduces relational queries, query-parameter filters, and eager loading.

  • Building Task Endpoints: A new router for tasks, mirroring the project router but with the relationship to Project in play.
  • Relational Queries & Filtering: where, join, and selectinload (the fix for N+1 queries when a response includes related data).
  • Database Fixtures with Pytest: The in-memory SQLite + StaticPool pattern, plus the fixture chain that builds sample data per test.
  • Exercise: Implement filtering in list_tasks and write two endpoint tests.