liveBook · Manning

Contract

As explained in The Design of Web APIs, Second Edition

An application programming interface is a defined boundary through which software components communicate and access capabilities or data.

A web API is a boundary through which a provider exposes capabilities to consumers over a network. A consumer sends an HTTP request describing an action and its needed data; the provider returns a response indicating the result. Consumers need to understand that exchange, not the provider’s database, code, or internal services. section 1.1 section 1.1.2 section 1.1.3

Sharing a message

A social-network mobile app can call POST /statuses to share a message, sending the message and an optional photo. The backend can store it and identify friends without requiring the mobile app to know whether that work involves other services or a particular database. The visible operation and data—not those internal choices—are what the consumer builds against. section 1.1.1 section 1.1.3 section 1.6.2

A useful API contract makes several choices clear to consumers:

  • Capabilities: which operations exist and what data they need and return. Missing operations or data can make a desired feature difficult or impossible to build. section 1.2.2 section 1.6.2
  • Behavior: use HTTP responses and errors consistently enough that consumers can understand failures and help end users recover. section 1.1.2 section 1.2.2
  • Access and volume: define who may see sensitive data, and avoid forcing consumers to retrieve an unbounded amount in one call. section 1.2.3 section 1.7.3
  • Change: assess existing consumers before renaming a response field or changing its meaning; either change can break them. section 1.2.4 section 1.3.2

A contract serves others even when an API is private: another team, a new colleague, or a future maintainer may consume it. Designing it around domain capabilities rather than one screen can also let a website, mobile app, and later clients use the same interface. Specific consumer needs still matter, so review the design with consumers, subject-matter experts, IT experts, and security experts. section 1.1.4 section 1.7.1 section 1.4.1 section 1.4.2

Before implementation, identify the capabilities consumers need, turn them into HTTP operations, and model their inputs and outputs. Describe the resulting interface in a standard API specification so stakeholders can check it against those needs. Revisit the design when development or early use reveals a gap—and treat later modifications as design decisions too. section 1.6 section 1.6.2 section 1.6.3 section 1.3.3

How The Design of Web APIs, Second Edition covers it

How deep it goes
Works through HTTP exchanges, operations, data, and design decisions, but stops short of implementation code and architecture.
Examples
Uses message sharing, POST /statuses, inconsistent identifiers, vague errors, exposed direct messages, and a renamed response field.
What it assumes
Introduces HTTP requests and responses without requiring prior familiarity with REST, SOAP, GraphQL, or gRPC.
What you can do after
Build it from scratch by identifying capabilities, designing HTTP operations and data, and describing the interface before implementation.
How it connects
Links the contract to HTTP, REST, API specifications, access control, pagination, and backward compatibility.

Also explained in

Compare how 45 books explain contract →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.