How it works · 7 of 38 Foundation
What is an API and how do APIs work?
How programs ask each other for things
APIs: An API is the published list of requests one program accepts from others: what you may ask, how to word it and what comes back, so programs can work together without seeing each other's insides.
Loading the animation…
Say it like this An API is the published menu of requests a program accepts and the answers it promises; you can rebuild everything behind it, but change the menu and every app that uses it breaks.
Under the hood — for builders
- One call, on this card's shop
- A web API call is a short message over HTTP (the language browsers and servers speak): a method and address, some headers (labels, including the key), and sometimes a body. The reply has a status code and usually a body in JSON (a plain-text format for data).
- Read the first digit
- Status codes come in families, so an app can react even to a code it has never seen.
- Four styles you'll meet
- REST: addresses for things, plus HTTP methods (GET reads, POST creates); most public APIs. GraphQL: one address, you name exactly the fields you want. gRPC: compact binary messages, common between a company's own services. Webhooks: the other side calls you when something happens.
- UPI: an API at national scale
- UPI is a published set of APIs run by NPCI that banks and payment apps all implement, so any app can pay any bank account.
- Versions
- Changes that add are safe; changes that rename or remove break callers. Owners version in the address (/v1/, /v2/), in a header, or by date, and announce a retirement date before switching an old version off.
- Watch out
- A key shipped inside a phone app can be read out of it: keep secret keys on your servers. Retry a payment only with an idempotency key (a unique id per attempt) so a retry isn't charged twice. Respect 429 and back off.
- Measure it
- Response time, errors by status family (4xx vs 5xx), and how close you are to each provider's rate limit.
- Sources
- RFC 9110 (2022) · RFC 6585 (2012) · RFC 2606 · NPCI UPI monthly statistics, August 2025, as reported 1 Sep 2025.
What happens in the APIs animation, step by step?
- Your app needs something from another program, say the price of item 42. It can't reach inside; it can only use the panel that program publishes: its API.
- It sends a request in the agreed form and gets an answer in the agreed form: here, 200 OK and the price as data. That's an API call.
- Your turn: ask the wrong way. Tap a request and read the machine's display.
- The shop rebuilds everything behind the panel. Your app doesn't notice: the panel didn't change. That's the promise an API makes.
- But change the panel itself, even one field's name, and every app using it breaks. So APIs carry versions: /v1 stays while /v2 is added.
- UPI is one shared API that every bank and payments app speaks: 20 billion payments in August 2025. Inside one company, should every part talk like this? Next: monolith vs microservices.
What everyday example explains APIs?
A vending machine. The buttons, the coin slot and the little display are its API: press B3 with a coin and crisps drop; no coin and the display says "pay first". You never see the machinery, and the owner can rebuild it as long as B3 still gives crisps.
Why should a team care about APIs?
You will decide which programs your product depends on and which you offer to others; an API is a promise, so check how its owner versions and retires it before you build on it, and keep your own stable once anyone else does.