When you check the weather on your phone, your phone doesn’t have a weather station inside it. The app sends a short message to a weather company’s computer, asking “what’s the weather in Pune right now?”, and a reply comes back with the temperature. The agreed way of asking and answering is called an API.
APIs are everywhere. Booking a cab, paying with UPI, logging in with Google, seeing a map inside a food delivery app: each of these is one piece of software asking another piece of software for something through an API. This guide explains what an API is, how one works, and why it is the first thing you design in almost any system.
What is an API?
API stands for Application Programming Interface. In plain words, it is a contract that says how one program can ask another program to do something, and what it will get back.
The easiest way to picture it is a restaurant:
- You (the customer) want food, but you don’t go into the kitchen.
- The menu tells you what you can order and how to ask for it.
- The waiter takes your order to the kitchen and brings back your dish.
- The kitchen does the real work. You never see how.
In software, your app is the customer, the API is the menu plus the waiter, and the server is the kitchen. The app doesn’t need to know what database the server uses, or what language it is written in. It just needs to follow the menu.
How an API call works: request and response
Most APIs you meet on the web work over HTTP, the same protocol your browser uses to load pages. Every call is a request followed by a response.
A request usually has four parts:
- An address (URL) that names the thing you want, such as
https://api.example.com/orders/42. - A method that says what you want to do with it. The common ones are
GET(read),POST(create),PUTorPATCH(change) andDELETE(remove). - Headers, small labels with extra information, such as who you are (an API key or token) and what format you want.
- A body (optional) with the data you are sending, often written in JSON, a simple text format of names and values.
The response comes back with:
- A status code, a three-digit number that says how it went.
- A body with the data you asked for, usually JSON too.
The status codes are worth learning because you will see them everywhere:
| Code | Meaning in plain words |
|---|---|
| 200 OK | It worked, here is your data |
| 201 Created | It worked, and a new thing was made |
| 400 Bad Request | Your request was wrong (missing or broken data) |
| 401 Unauthorized | We don’t know who you are (not signed in) |
| 403 Forbidden | We know who you are, but you aren’t allowed |
| 404 Not Found | That thing doesn’t exist |
| 429 Too Many Requests | Slow down, you’ve hit a limit |
| 500 Internal Server Error | Something broke on our side |
A simple rule of thumb: codes starting with 2 mean success, 4 mean the caller made a mistake, and 5 mean the server made one.
An everyday example: tracking a food order
Say you open a food delivery app to see where your order is. Behind the scenes, something like this happens:
GET /orders/42 HTTP/1.1
Host: api.example.com
Authorization: Bearer eyJhbGciOi...
The server checks the token, looks up order 42 in its database, and replies:
{
"id": 42,
"status": "out_for_delivery",
"etaMinutes": 12
}
The app reads etaMinutes and shows “Arriving in 12 min”. That’s it. The app never touched the database; it only asked through the API.
Why APIs matter in system design
When engineers design a system, the API is usually the first thing they write down, even before choosing a database. There are good reasons for that.
- It is the promise to the outside world. Mobile apps, websites and partner companies all build against it. Once people depend on it, changing it is hard (that’s why API versioning exists).
- It hides the inside. Because callers only see the API, the team can change the database, split a service in two, or add a cache without breaking anyone.
- It defines the load. Knowing the calls (“get order”, “place order”) and how often they happen tells you how much traffic each part of the system must handle. That’s the start of estimation.
- It is where protection lives. Sign-in checks, rate limits and input checks all sit at the API’s edge, often in an API gateway.
Kinds of APIs you’ll hear about
“API” is a broad word. The styles you’ll meet most in system design are:
- REST: the most common style on the web. Things are nouns in the URL (
/orders/42) and HTTP methods are the verbs. - GraphQL: the client sends one query describing exactly which fields it wants, and gets just those back.
- gRPC: a fast, binary style popular for calls between services inside a company.
- WebSockets: a connection that stays open so the server can push updates, useful for chat and live tracking.
- Webhooks: the reverse direction, where a server calls you when something happens. See what a webhook is.
Our deep dive on REST vs gRPC vs GraphQL vs WebSockets compares them side by side.
Common misconceptions
“An API is a website.” No. A website is made for people to look at. An API is made for programs to read, so it returns data (like JSON), not pretty pages.
“API means the server.” The API is the contract: the list of requests you can make and the answers you get. The server is the machine that keeps that promise.
“APIs are only on the internet.” Programs on one computer use APIs too. When an app asks your phone for its location, it uses the phone’s location API.
“An API key keeps everything secure.” A key says which app is calling. Security also needs proper sign-in for users, permission checks and HTTPS. Our guide to security in system design covers the rest.
Key takeaways
- An API is a contract for how one program asks another for something.
- Web APIs work as a request (URL, method, headers, body) and a response (status code, data).
- Status codes starting with 2 mean success, 4 caller error, 5 server error.
- In system design, the API is the front door: it hides the inside, defines the load and is where protection lives.
- Design the API first, then the parts behind it.
Frequently asked questions
What is an API in simple words?
An API is a set of rules that lets one program ask another program for data or to do a task. It works like a waiter in a restaurant: you order from the menu, and the waiter brings back what the kitchen made.
What is an example of an API?
When a travel site shows flight prices from many airlines, it calls each airline’s API to ask for prices. When an app lets you “Sign in with Google”, it uses Google’s sign-in API.
What is the difference between an API and a REST API?
API is the general idea of a contract between programs. A REST API is one popular style of web API, where each thing has a URL and HTTP methods like GET and POST say what to do with it.
Is an API the same as a database?
No. A database stores data. An API is the front door in front of it. Callers ask the API, and the server behind the API decides how to read or change the database.
Do I need to know coding to understand APIs?
No. Understanding the idea of requests, responses and status codes is enough to follow system design discussions. Writing code to call an API is the next step if you want to build things.
Comments