What Is an API? The Restaurant Waiter Analogy
APIs let apps talk to each other without knowing each other's secrets. Learn what they are with a simple restaurant story, and see how a weather app uses one.
Every time you check the weather on your phone, pay with UPI, or log in with Google, apps are talking to other apps. The way they do it is called an API, short for Application Programming Interface.
The restaurant story
You sit at a table in a restaurant. The kitchen can cook anything on the menu, but you cannot walk in and cook. Instead, a waiter takes your order to the kitchen and brings the food back.
- You are the app that needs something.
- The kitchen is the system that has the data or ability.
- The waiter is the API. It takes a request in a known format and returns a response.
The menu shows what you can ask for. You do not need to know how the kitchen works, and the kitchen does not need to know who you are or how you eat.
A real example: a weather app
You open the app
It wants today's temperature.
The app sends a request
It contacts the weather service's API and says: "Give me the weather for Pune."
The service checks the request
It might check a secret key, called an API key, to confirm you are allowed.
The service replies
It sends back data, often in a format called JSON, like `{"city":"Pune","temp":29}`.
The app shows it to you
It turns the data into a nice screen with icons.
Where you see APIs every day
- Sign in with Google or Facebook. The website asks Google's API to confirm who you are.
- Online payments. A shopping site asks a payment company's API to take your money.
- Maps inside apps. A food delivery app uses a map service's API to show your order.
- Travel booking. One site compares prices by calling many airline APIs.
Why APIs matter to businesses
APIs let companies build on each other's work instead of starting from zero. A small startup can add payments, maps, and messaging in days, because other companies offer those as APIs.
What most people miss
- APIs have rules and limits. Most limit how many requests you can send per minute, to keep the service stable.
- API keys are secrets. If a developer accidentally publishes one online, others can misuse it.
- A good API is stable. Many apps depend on it, so changes are announced carefully.