A menu and a waiter: a clear way for one program to ask another for something.
An API (Application Programming Interface) is a clear way for one program to ask another program for something, and get an answer.
An API is a contract between two pieces of software. It says: “If you send me a request like this, I will send you a reply like that.”
You use APIs inside one program too (a function you call in a library). In system design we mostly mean network APIs: one program calls another over the internet or inside a data centre, usually with HTTP.
Modern software is made of many parts. They all need a clean way to talk.
| Kind | Who uses it | Example |
|---|---|---|
| Public (open) API | Any developer, often with a key | A weather or maps API |
| Partner API | Chosen business partners | A bank API for approved apps |
| Private (internal) API | Only your own teams and services | Order service calling stock service |
Every network API call has the same few parts. Learn these once and you can read any API.
| Range | Meaning | Examples |
|---|---|---|
| 2xx | Success | 200 OK, 201 Created, 204 No Content |
| 3xx | Go somewhere else | 301 Moved, 304 Not Modified |
| 4xx | Your mistake (the client) | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests |
| 5xx | Our mistake (the server) | 500 Internal Error, 503 Service Unavailable |
GET /weather?city=Pune HTTP/1.1
Host: api.example.com
Authorization: Bearer <your-token>
Accept: application/json
--- response ---
HTTP/1.1 200 OK
Content-Type: application/json
{ "city": "Pune", "tempC": 29, "sky": "Sunny" }/orders/42, not /getOrder?id=42./v1/) before you need it.| Term | Meaning in easy words |
|---|---|
| Endpoint | One URL plus a method that does one job, like GET /users/7 |
| Request / Response | The message the client sends / the message the server sends back |
| HTTP method | The action: GET (read), POST (create), PUT (replace), PATCH (change a part), DELETE (remove) |
| Status code | A number that says how it went (200 OK, 404 Not Found, 500 Server Error) |
| Header | Extra information about the message, like the format or a login token |
| Payload / Body | The actual data sent in a request or response |
| API key | A secret string that tells the server which app is calling |
| Rate limit | A cap on how many calls you can make in a period of time |
| Versioning | Keeping old and new forms of an API side by side (/v1, /v2) so old clients keep working |
| SDK | A ready-made code library that wraps an API so you do not write raw requests |
| OpenAPI | A standard file format to describe a REST API, so tools can make docs and code from it |
| Contract | The agreed rules of the API. Breaking it breaks the clients |
| Choice | We gain | We lose |
|---|---|---|
| Small, simple API | Easy to learn and use | Clients may need many calls |
| Big, flexible API | Fewer calls, more power | Harder to learn, secure and keep stable |
| Public API | Growth, partners, ecosystem | Support work, abuse, and you cannot easily break it |
| Strict contract | Safe for clients | Slower to change |