API design answers the question of what an interface looks like from the outside. The design determines which resources it offers, which operations are used to call it, which data it accepts and returns, and how it responds to errors. The result is a specification, a contract between those who provide the API and those who use it. Why this contract is created before the code is explained in the section “What is API First?” on the API Services page. This page is about the work on the design itself.
What an API design defines
Designing a REST API involves several decisions that have to fit together. The resource model determines which business objects the API offers and under which paths. For every operation, it is settled which HTTP method it uses and which status codes it responds with. Data models describe requests and responses, and an error model describes the response when something goes wrong. Added to this are the access mechanism and the rules under which the interface may change later.
OpenAPI, the design as a machine-readable specification
The OpenAPI Specification defines a standard, programming-language-agnostic description for HTTP APIs. An OpenAPI document is written in YAML or JSON and contains paths, operations, parameters, data schemas, and security mechanisms. Recurring building blocks are defined once in the components section and referenced from there. Because the document is machine-readable, tools can generate documentation and code from it and derive tests. In our projects, we have described interfaces in RAML and in OpenAPI.
API First and why a careful design matters
An agreed contract allows several parties to work at the same time. In the integration of SugarCRM and SAP R/3 for a publishing company, the API design was our responsibility. RAML fragments and business types defined what a customer or an order looks like across all interfaces, and the client, the service provider, and dataliquid worked against the same contracts. For the tariff comparison calculator of an energy utility, every interface was first designed as a RAML specification. An agency built the user interface of the calculator, and it obtains the finished comparison through a REST API.