Skip to course content
Free FastAPI backend course

FastAPI for AI Backend Development

Module 06 Activity

Scenario

Make the responses and errors something a client can rely on and handle.

What you build

Response models that filter, structured errors with stable codes, declared error responses and a versioning plan.

Steps

  1. Add a response model to every endpoint and prove it filters a field the handler returns.
  2. Give every error a stable machine-readable code alongside the human text, plus enough context to act on.
  3. Use 201 with a Location header for creation and 204 where a body would be meaningless.
  4. Declare every error response in the contract so callers see them without reading your source.
  5. Classify a list of proposed changes as safe or breaking, paying attention to enum direction.
  6. Write the versioning plan for the first breaking change you expect.

Evidence to hand in

Review checklist