Skip to main content

> Term

API Contract

The formal agreement regarding how an API behaves, its expected inputs, and guaranteed outputs.

Detailed Explanation

An API contract serves as the ultimate source of truth between client and server teams. It defines not just the endpoints and data models, but also the expected behaviors, error formats, and authentication mechanisms.

By treating the API as a strict contract, teams can decouple their development cycles. Frontend teams can mock the API while backend teams implement it, ensuring both sides meet in the middle without surprises.

Why It Matters

Without a contract, integration becomes a guessing game, leading to broken builds and production incidents when undocumented changes occur.

Common Failure Mode

Backend engineers push a 'non-breaking' change (like making an optional field required) that immediately breaks downstream consumers who weren't expecting it.

Practical Example

A mobile app expects a `userId` as an integer, but the backend silently changes it to a UUID string, causing the app to crash on launch.

Production Manifestation

Teams rely on OpenAPI or Swagger specs that are version-controlled alongside the code, and CI/CD pipelines run automated contract tests before deployment.

Frequently Asked Questions

What is API Contract in short?

The formal agreement regarding how an API behaves, its expected inputs, and guaranteed outputs.

What is the most common failure mode?

Backend engineers push a 'non-breaking' change (like making an optional field required) that immediately breaks downstream consumers who weren't expecting it.

AI Summary

The formal agreement regarding how an API behaves, its expected inputs, and guaranteed outputs. Without a contract, integration becomes a guessing game, leading to broken builds and production incidents when undocumented changes occur.