Interface & API Specification
Interface & API Specification
Once a system has been decomposed into modules and components, every point where two pieces of software meet becomes a design risk. If the meeting point is not precisely defined in writing before a single line of code is written, both sides will make different assumptions and the integration will fail. That formal written definition of a meeting point is called an interface specification. When the meeting point is exposed over a network (HTTP, messaging, sockets), the specification is commonly called an API specification.
This lesson teaches you how to author these contracts: what they must contain, how to structure them, and how to validate them against the requirements you captured earlier in the project.
What an Interface Specification Covers
A complete interface specification answers six questions:
- Who calls whom? — identify the caller (client) and the provider (server or module).
- How is the call made? — the protocol, transport, and invocation pattern (synchronous request/response, async message, callback, event).
- What does the caller send? — input parameters: names, data types, constraints, and whether each is mandatory or optional.
- What does the provider return? — output fields: names, types, and meaning of each value in the successful response.
- What can go wrong? — error cases: codes, messages, and the conditions that trigger each one.
- What are the non-functional expectations? — latency SLA, throughput limit, authentication method, idempotency guarantee.
Anatomy of a REST API Endpoint Specification
Modern systems commonly expose REST APIs over HTTP. The structure below specifies a single endpoint from a clinic booking system where the front-end scheduling module calls the appointment service:
Notice that every error case has a distinct error_code string. Generic messages like "error": "something went wrong" force the calling developer to guess; explicit codes allow the caller to handle each case programmatically — retry on 409, redirect to login on 401, show a field validation message on 400.
The Interface Diagram: Visualising Contracts Between Components
A diagram that maps all the interfaces in a subsystem is invaluable during design reviews. Each component is shown as a box; each interface is an annotated arrow carrying the call name and protocol. The diagram below shows the four main interfaces inside the booking subsystem of the clinic platform:
Each interface receives a unique identifier that can be referenced in traceability tables, design reviews, and test plans. Solid lines indicate synchronous calls; the dashed line for IF-2 indicates an asynchronous event published to a message queue — the publisher does not block waiting for a response.
Specifying Asynchronous and Event-Driven Interfaces
In an event-driven design the provider publishes an event and does not wait for a response. The specification must therefore document the event shape rather than a response schema:
event_id. Subscribers check whether they have already processed that ID before acting. Document this requirement explicitly in the spec — it is easy to overlook and hard to fix after deployment.
API Specification Standards and Tooling
Writing specs in free-form prose is error-prone and hard to keep in sync with reality. Industry-standard machine-readable formats solve this:
- OpenAPI 3.x (formerly Swagger) — the dominant standard for REST APIs. A YAML or JSON file that describes every endpoint, request body, response schema, and error code. Tools such as Swagger UI render it as interactive documentation; code generators produce client stubs in dozens of languages.
- AsyncAPI — the event-driven counterpart to OpenAPI. Describes channels, message payloads, and bindings for Kafka, RabbitMQ, and MQTT.
- Protocol Buffers (.proto files) — the schema language for gRPC interfaces. Strictly typed; the compiler enforces the contract and generates client/server code in multiple languages.
- GraphQL Schema Definition Language (SDL) — for GraphQL APIs, the SDL file is the spec; queries are validated against it at build time.
/api/v1/ vs /api/v2/) when breaking changes are introduced. Consumer teams must be notified of breaking changes before deployment.
The Interface Register: Tracking All Contracts in a Project
On a project with dozens of components, a single table — the interface register — gives the project manager and architect a complete picture of integration dependencies. Each row is one interface:
The status column (Draft / In Review / Approved) makes it immediately visible which interfaces are still unresolved risks. A project cannot enter the build phase until every interface it depends on reaches Approved status.
From Requirements to Interface Spec
Every interface specification should trace back to one or more functional requirements. For the clinic booking endpoint POST /api/v1/appointments, the traceability chain looks like this:
- FR-12: The system shall allow patients to book available appointment slots with a specific doctor.
- FR-13: The system shall prevent double-booking of a doctor at the same time slot.
- NFR-04: The booking API shall respond within 800 ms at the 95th percentile under normal load.
Each requirement drives a specific part of the spec: FR-12 drives the request body fields; FR-13 drives the SLOT_UNAVAILABLE 409 error; NFR-04 drives the latency SLA documented in the non-functional section. When a requirement changes, the analyst knows exactly which interface spec must be updated — and which development team must be notified.
A well-written interface specification is one of the most leverage-rich artefacts in system analysis. It eliminates integration surprises, enables parallel development, forms the basis for integration test cases, and serves as the authoritative reference when disputes arise between teams months into the build.