Currently Available: Need a skilled Software Developer for your next project?
Categories
APIs

Why Your API Is a Contract, Not Just Technology

When one service sends a request to another, the receiving service exposes an API, or application programming interface. That API defines the operations and data that let separate pieces of software work together. The client calling the API depends on the provider to send back responses it can understand.

In software engineering, an API contract spells out what a provider promises and what consumers can rely on. It covers visible details, such as request fields and response formats, along with behavior, such as what a field means or what an error indicates. The word contract here refers to an engineering agreement; it does not establish a legally enforceable contract on its own.

When you treat an API as a contract, you check whether existing consumers can still send requests, read responses, and get the results they expect before you release an update. You test those expectations, and when a change breaks them, you give consumers a clear path to move to the new version.

The contract covers behavior and meaning

An API specification describes the interface that consumers can call. For an HTTP API, the OpenAPI Specification gives you a machine-readable format for describing paths, operations, schemas (the shape of request and response data), and related details. That description helps people and tools understand the interface, though it does not prove that a running service actually matches it.

Consumers rely on more than the shape of a response. They also depend on what fields mean, which inputs are required, how the server handles omitted values, and what different errors signal. Pagination and webhook delivery behavior, for example, directly affect how consumers retrieve records and handle events. When you document pagination behavior and webhook delivery semantics, you make those expectations explicit.

Write down the behavior consumers should depend on, including defaults, error meanings, and any operational limits that matter. Also state which behavior is unsupported or subject to change. Clear boundaries give consumers better guidance and give API owners room to change implementation details they never promised to preserve.

Small changes can break existing clients

You can keep an API's URL the same and still break a consumer. Google’s backward-compatibility guidance separates compatibility into three kinds:

  • Source compatibility: Whether code using an updated client library still compiles and runs.
  • Wire compatibility: Whether an older client and a newer server can still exchange and interpret serialized data.
  • Semantic compatibility: Whether the client still gets the behavior it reasonably expects.

Consider an order API that returns a status, where a client handles PENDING, PAID, and CANCELLED. If the provider adds REFUNDED, the response still fits the same general shape, and the client may still parse it. Even so, client code that assumes every status matches one of the original three values can fail or process the order incorrectly.

Other small changes carry similar risks. If you make an optional request field required, older clients will send requests that fail. If you change a default value, a client can get a different outcome even when it sends the exact same request. And if you change when a response field appears or what its value means, clients may make the wrong decisions.

Clients that ignore unknown fields usually handle additive changes, such as a new optional response field, without trouble. The provider still has to handle older requests that omit newly introduced fields. Check how consumers parse and use the data before you assume an additive schema change is safe.

A 2017 study of Java libraries found that 14.78% of API changes broke compatibility with earlier versions. Based on references to the changed types, the study’s median estimate was that 2.54% of client applications could be affected by breaking changes. Those figures come from Java libraries rather than web APIs, and the client-impact measure does not prove that every affected application failed at runtime. The study shows that compatibility breaks happen, even though it cannot predict the risk of a specific API change. The study’s findings and limitations are a good reason to check compatibility deliberately.

Test the promise at more than one level

A specification, a contract test, and a functional test each answer a different question. A specification describes the interface. A contract test checks whether a particular consumer-provider interaction matches agreed expectations. A functional test checks whether the service performs its intended work, such as saving an order or issuing a refund.

With Pact’s consumer-driven contract testing, a consumer records the interactions it needs, and the provider verifies its implementation against them. That catches a mismatch in a request or response used by a known consumer, though it does not prove that every possible client interaction works or that the provider completed the intended business action. Pact draws a clear line between contract testing and functional testing, and notes that contract testing also depends on collaboration between consumers and providers.

Use these checks together. Keep the API specification aligned with the running service, and check proposed changes for compatibility with existing requests and responses. Pair contract tests for important consumer interactions with functional tests for side effects, and use production monitoring to catch behavior that tests miss.

Make breaking changes deliberate

API owners cannot preserve every behavior forever. Teams that support old versions have to maintain extra code, run more tests, and handle more operational work. The cost and risk depend partly on who consumes the API. An internal provider and its consumers can coordinate an update, while a public provider may have no control over when external clients change. Microsoft’s API design guidance covers both compatibility patterns and the costs of maintaining multiple versions.

Before you remove or change behavior, identify your consumers where possible and inspect how they use the API. Consumers sometimes rely on behavior the provider never intended as a guarantee. Software Engineering at Google describes this through Hyrum’s Law: with enough users, someone will depend on every observable behavior. That principle does not force you to preserve every accidental detail forever, but it is a strong reason to check real usage before you make a consequential change.

When a change breaks compatibility, explain what is changing and how consumers should adapt, then choose a transition approach that fits your audience. Providers and consumers who can enforce updates can coordinate a direct cutover. When consumers need time to migrate, offer a separately versioned interface and keep the old version running during a deprecation period. There is no universal timeline for that transition. For example, the New Zealand Government’s API Standard, version 2026-09-01 requires its agencies to version APIs at publication or when a change is breaking, and to maintain an older version alongside a new one for an appropriate transition period. That requirement applies within the standard’s scope, and other teams have to pick a timeline that fits their own consumers.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Email updates

Usually a new article and a few links I found interesting.

No spam. Unsubscribe with one click.

Leave a Reply

Your email address will not be published. Required fields are marked *