Lessons › coding and computer science · taught by Leo
APIs explained: how apps talk to each other
Learn how APIs pass requests and responses between apps and servers, and why they act like a rulebook for software communication.
Learn this with Leo, freeA voiced lesson with a live whiteboard, quizzes and a tutor you can call, at tutelage.appWhat an API does
Think of an API like a waiter in a restaurant. You do not go into the kitchen yourself.
You ask the waiter for something, and the waiter carries the message to the kitchen.
That is what an API does between two pieces of software.
Big idea: a contract
An API is a contract for how programs talk.
It tells you what to send, what you get back, and what shape the data should have.
It helps two different systems work together without knowing each other's code.
Predict the API role
If your app asks a weather service for today’s forecast, what is the API doing?
- Passing the request and response between them
- Turning rain into sunshine
- Deleting the app’s data
Show answer
Passing the request and response between them: Yes. The API is the messenger and rulebook for the exchange.
Request then response
First the client sends a request. The client is the app asking for something.
Then the API forwards it to the server and checks the format.
Finally the server sends back a response, and the app uses the data.
A simple API call
Here is a tiny example. The app asks for weather in Boston.
A successful response might start with 200 OK. That means the request worked.
Then the data comes back, often in JSON, which is a neat text format for objects.
Quick check: which part next?
After sending a GET request, what is the most likely next thing to happen?
- The server sends back a response
- The API erases the request
- The app becomes the server
Show answer
The server sends back a response: Right. The next step is the response coming back.
Why APIs are useful
APIs save time. You can use a maps API instead of building maps from scratch.
They also separate jobs. One team can build the app, and another can build the service.
That makes software easier to reuse, update, and connect.
API terms to know
Request means what you send out. Response means what comes back.
You do not need to memorize every term at once. Just remember the direction.
Common mistake to avoid
A common mistake is thinking the API is the whole app.
It is not. The API is the doorway, not the whole building.
The real work happens inside the client and server.
Your turn: what is the API?
Which description best fits an API?
- A rulebook and messenger between programs
- A database that stores all files
- A screen layout for buttons
Show answer
A rulebook and messenger between programs: Good. That is the best match: a rulebook and messenger between programs.
API checklist
Here is the whole flow. Send a request.
The API routes it, the server answers, and your app uses the response.
If you remember that flow, you understand the core idea of APIs.