SA-301d · Module 1

API-First Design

3 min read

API-first design means the API contract is designed, documented, and agreed upon before any implementation begins. The OpenAPI specification or GraphQL schema is the deliverable of the design phase, not a byproduct of the implementation phase. This inversion changes everything — the consumer reviews the contract before the producer writes a line of code, which catches design problems when they cost minutes instead of sprints.

  1. Design the Contract Write the OpenAPI specification or GraphQL schema first. Define every endpoint, every request body, every response shape, every error code. This specification is the contract that consumers will build against. Review it with consumers before implementation. The review catches over-fetching, missing fields, and awkward patterns that would be expensive to fix after implementation.
  2. Mock Before Building Generate a mock server from the specification. Consumers can begin integrating against the mock immediately — testing their clients, building their UIs, and discovering contract gaps — while the producer implements the real service. Parallel development reduces the critical path and surfaces integration issues early.
  3. Generate and Validate Generate server stubs and client SDKs from the specification. Validate every implementation response against the specification in CI. The specification is not documentation — it is the source of truth. Any response that deviates from the specification is a contract violation, and the CI pipeline should catch it before deployment.