You are a student who needs a rare book for your project. The book sits somewhere in the library's archive: endless shelves, dusty boxes, trolleys and staff who all know their own sections.
You could try walking in and finding it yourself. But you don't know how anything is shelved, you'd be in everyone's way, and a hundred other students would try the same.
Life has many situations like this. A farmer wants to sell grain in a huge, crowded wholesale market. A traveller wants a train ticket from a railway office buzzing with files and staff. In each case, one side wants something from a busy place, and neither side should have to understand the other's inner workings.
How can a request go in and the book come back, without anyone having to enter the mess? Let's find out by playing ๐
How to play: press Auto to watch the story play by itself, or click through step by step. Pause, Next and Speed are always there if you need them.
Play through the library. When the game ends, the Continue button unlocks.
You just used a clever idea without knowing its name. First, let's reflect on what you saw. The name comes in Chapter 5.
Think about these in your own words before moving on.
The librarian you invented has a name in the software world.
What happened in the library:
Now we can give names to what you did. In the world of computers, the librarian's job has a name: the API.
An API (Application Programming Interface) is a way for one piece of software to ask another for something, and get an answer back, without knowing how the other one works inside.
| Library Story | Software Concept |
|---|---|
| Student | Client (an app or website) |
| Librarian and the way of requesting | API |
| Archive | Server |
| Request slip | Request |
| Book coming back | Response |
| The fixed way of requesting | Interface (the agreed rules) |
| Catalogue | Documentation of what you can ask for |
| Archive rebuilt, requesting unchanged | Server changes behind a stable API |
An API lets you use a system without knowing what happens inside it.
Every conversation has two parts: you ask (request), and you get an answer (response).
As long as the way of asking stays the same, the inside can be rebuilt freely.
Weather apps, UPI payments, maps in delivery apps, and mandi-price apps all use APIs.
Apply what you learned to new situations. Think through each one before moving on.
Which of these work like a libraryโs request desk: a power socket, a restaurant waiter, cooking Maggi at home, or UPI payment at a shop?
For each example that does not work like a request desk, what is missing? Identify what makes something an API.
Imagine a library has an archive where all books are stored. Students cannot access the archive directly; they must submit a request through a request desk.
What information must every request include? What different responses could the archive send back besides โHere is your bookโ?
If you were designing this as an API, which HTTP methods would you use to request, add, update, or remove information?
A universityโs mobile app and website maintain separate attendance records, which often disagree.
How would you design one system so both applications access the same data and always display consistent attendance information? What role would an API play in this system?
Students view marks, teachers update marks, and parents view their childโs marks, all from one database.
How would you design the API so each user can access only the information and operations they are authorized to use? How would the system identify and verify each user?
A weather app sends 50 separate requests for 50 cities every time it opens.
How could you make this process faster and reduce unnecessary API requests? Could you retrieve multiple citiesโ weather information together or temporarily store previously received results? How long should a saved weather result be considered valid?
A cab booking request is successfully processed, but the confirmation message gets lost. The customer assumes the booking failed and taps โBookโ again.
How would you prevent the system from creating two bookings for the same request while still allowing the customer to retry safely?
A library now wants every request slip to include a student ID, but thousands of students are still using the old version of the slip.
How would you introduce this change without breaking the existing system? How does the same problem occur when an API is updated while older applications are still using it?
Imagine designing a hospital system with separate departments for reception, laboratory, pharmacy, and billing.
How would you design the APIs for these departments so they can communicate and exchange information? Where does the library request desk analogy stop working when applied to a real software system?