What is an API? Interfaces explained clearly
An interface is an agreement between two systems: who asks what, who answers what, and what applies when something goes wrong. The last part is the most important — and the one most often missing in projects.
What you will learn
An interface is an agreement
When a shop passes an order to the inventory management system, the two systems do not simply talk to each other. There is a defined place where one system can make a request, a defined form for that request, a defined form for the response — and an agreement on what applies when something is missing.
This agreement is the interface, in English an Application Programming Interface, or API for short. The technical part is often the easier one. The difficult part is agreeing which fields are mandatory, which values are permitted and who decides in the event of contradictions.
How a request works
System A · Shop
- Order is placed
- Request to the interface
- Waits for response
Interface
- Checks login and permissions
- Checks the data for completeness
- Translates fields and formats
- Responds: accepted, or rejected with a reason
System B · Inventory management
- Creates the order
- Returns an order number
- Rejects if an item is unknown
Three things stand out in this diagram. First: the interface checks before it passes anything on — otherwise faulty data ends up in the target system. Second: it translates, because two systems almost never name the same thing the same way. Third: it also responds when it rejects something, and does so with a reason.
Polling or being notified
There are two basic patterns, and the choice between them has practical consequences.
In practice the two are often combined: notifications for the normal case, a regular poll as a safety net underneath. This duplication is not extra effort without reason — it is the answer to the question of what happens when a message is lost.
An example from practice
The order nobody saw
A shop reports every order to the inventory management system by notification. On a Tuesday the inventory management system is unreachable for twenty minutes. The shop sends the messages, gets no response — and discards them. Four orders are missing, and it will only be noticed at the monthly reconciliation.
The solution is not more technology but an agreement: messages are repeated until they have been confirmed, and anything that still has not arrived after several attempts ends up in a list that a person sees. This includes the rule that a message delivered twice does not create a second order.
The failure case is half the work
An interface that works in the normal case is half finished. This includes:
These four points distinguish an interface you can operate from one that works only as long as nobody is looking.
Six questions before any interface
Anyone who answers these six questions before building has the difficult part behind them. Anyone who skips them will answer them later in operation — under time pressure.
Common misconceptions
Further sources
- RFC 9110 — HTTP Semantics the standard behind requests, responses and status codes
- RFC 9457 — Problem Details for HTTP APIs a uniform format for error responses
About the author
Fabian Lücker is managing partner of PHP-Schmiede KG in Rheine and has worked in software development since 2007. He is responsible for development and design, and writes here about decisions that come up in real projects.
Two systems that do not know each other?
Tell us the two sides and what is to be transferred. We will work through the six questions with you.