Skip to content

HTTP API Design

The goal of this page is to provide you with a single source of guidance on what to review and prepare for ahead of Quiz 2. The goal of the quiz is to assess your understanding of key concepts, ideas, and skills we have covered since the last quiz.

Task Learning Objectives

The emphasis since the last quiz has been on Task 6: Designing an HTTP API and testing it.

Task 6: Part One

After completing part one, you should be able to:

  1. Translate user stories into an HTTP API design
  2. Design an API interface before implementation
  3. Define route signatures with decorators (using FastAPI)
  4. Model request and response data with Pydantic
  5. Describe the value in professional OpenAPI documentation for other developers (e.g. using /docs to understand an API)
  6. Apply validation constraints in API design
  7. Consider non-success responses and edge cases
  8. Evaluate API design quality using criteria

Task 6: Part Two

Implementation concerns

After completing part two, you should be able to:

  1. Separate concerns across route, service, and storage layers
  2. Implement a story from route, to service, to storage integration
  3. Utilize dependency injection for HTTP request data in routes
  4. Utilize dependency injection for instances of objects from within the same layer of abstraction (e.g. route/HTTP concerns) or the layer beneath (e.g. routes injecting service layer objects, services injecting persistence layer objects)
  5. Understand why .gitignore and .gitkeep files are used to avoid commiting mutable runtime data while preserving directory structure

Testing

In this quiz, you will not need to write syntax for tests, however you will be asked to describe in technically precise English what steps you would need to perform in the Arrange, Act, and Assert steps of these scenarios.

You will also be asked to describe specifically what a particular test verifies or proves. In other words, what is the value of a specific test in a test suite?

After completing part two, you should have a conceptual understanding of how to do achieve the following verification tasks:

  1. Write automated unit tests that isolate a single component
  2. Write automated integration tests that verify the coordination between one or more components
  3. Write end-to-end tests from HTTP routing to persistence
  4. Understand the purpose of each step of an Arrange, Act, Assert style test
  5. Understand what FastAPI's dependency_overrides is needed for. Why is it needed in tests that utilize TestClient, but not impactful in unit tests and integration tests that do not utilize TestClient? Having a clear understanding of this is important to your understanding of the role of dependency injection systems and how to test software architectures that utilize DI. For a given test, focus on where the initial call to your route function with dependency injected parameters originates: is it directly and explicitly called in your test code or is it indirectly called from within the framework (FastAPI)?

Lesson Learning Objectives

LS10 - LS13

The learning objectives of these lessons are covered in the task and reading learning objectives.

LS14 - Testing with Dependency Injection

This lesson introduced an important diagramming technique to depict the relationship between dependency injected parameters and their providers. Additionally, we diagrammed the type of value that is produced by a provider and injected. By diagramming these relationships between components, you have a direct, visual understanding of what:

  1. The objects you will need to arrange for a test (injected parameters)
  2. The results you want to assert in a test
    1. Expected collaborations with mocked components from underlying layers
    2. Expected result returned from the test subject

Reading Learning Objectives

RD14 - Key Concepts in HTTP

  • Explain HTTP as the standard protocol clients and servers use to communicate in modern apps.
  • Define resources and interpret URLs as identifiers for what an API operates on.
  • Differentiate common HTTP methods (GET, POST, PUT, PATCH, DELETE) by purpose, including safety and idempotency.
  • Identify the key parts of HTTP requests and responses (method/URL, headers, body, status line).
  • Interpret HTTP status codes as server feedback, including common success, redirect, client-error, and server-error responses.

RD15 - Toward Designing and Formally Specifying APIs

  • Identify the major inputs to an HTTP API request (method, path, query parameters, body, headers) and explain the role each plays in API design.
  • Explain core RESTful design ideas, especially resource-oriented URLs and stateless request handling, and apply them when designing APIs.
  • Differentiate when to use path parameters vs query parameters (resource identity vs filtering/sorting/refining results).
  • Apply common API path/query design conventions (resource nouns, plural collections, IDs in paths, filters in queries, consistency, and shallow nesting).
  • Specify expected API responses by pairing HTTP status codes with response body schemas (especially success and client-error cases).

RD16 - FastAPI and Pydantic Tutorial

  • Understand how FastAPI route decorators (e.g., @app.get, @app.post) map HTTP methods and paths to Python handler functions.
  • Understand how Pydantic models specify request/response schemas and enable FastAPI’s automatic parsing and validation.
  • Understand how to implement basic CRUD endpoints in FastAPI (GET, POST, PUT, DELETE) for a resource, including dynamic path parameters.
  • Understand how API errors are handled with HTTPException and appropriate HTTP status codes (e.g., 400, 404, 201, 204, 422).
  • Understand how FastAPI’s automatic OpenAPI documentation (/docs, /openapi.json) can be used to inspect, test, and understand API behavior.

RD17 - Dependency Injection

  • Understand what dependency injection is and how FastAPI uses Depends() to construct and inject dependencies into route handlers.
  • Understand why dependency injection improves modularity, maintainability, flexibility, and testability compared to constructing dependencies inside route bodies.
  • Understand how to separate business logic into service classes that remain independent of HTTP/FastAPI concerns.
  • Understand how FastAPI resolves dependencies at request time (routing, dependency resolution/instantiation, then handler execution).
  • Understand how Annotated and TypeAlias can be used to define reusable dependency-injected types (for example, a GameServiceDI alias) to reduce repetition and centralize DI configuration.

RD18 - On Pair Programming

  • Understand pair programming as a collaborative software development practice that improves code quality and team effectiveness beyond simply "two people at one computer."
  • Understand common pairing styles and roles (especially driver/navigator, ping-pong, and strong-style pairing) and when each is useful.
  • Understand how pair programming supports key outcomes such as knowledge sharing, continuous code review, focus, collective code ownership, and onboarding.
  • Understand common challenges of pairing (fatigue, skill gaps, interruptions, power dynamics, vulnerability, and context switching) and practical strategies to address them.
  • Understand pair programming as a "sensible default" to adapt contextually (rather than dogmatically), including how it complements code review, rotations, and team workflow practices.

RD19 - Unit, Integration, and End-to-End Testing API Routes

  • Understand the purpose and scope of unit, integration, and end-to-end (E2E) tests for API routes, and what each level is intended to prove.
  • Understand how to unit test a FastAPI route handler in isolation using AAA structure and mocked dependency-injected services.
  • Understand how to write integration tests with TestClient that exercise FastAPI routing + route handlers + service logic while patching specific side effects (e.g., randomness).
  • Understand how and where to patch correctly in Python tests ("patch the name where it is used"), especially for imported/aliased functions.
  • Understand how parametrization and regression tests improve API test coverage, including testing multiple valid outcomes and important invalid-input behaviors (e.g., 422 responses).

Quiz Format

The constrained choice questions will focus on assessing your understanding of the readings. The open ended questions will focus on assessing your understanding of the work you completed in the tasks.