What is an API — Simple Explanation with Examples
An API (Application Programming Interface) is a set of rules and protocols that allows one software application to request data or services from another application. It defines the methods and data formats that programs use to communicate, acting as a contract between the caller and the provider.
What You’ll Learn
By the end of this article, you’ll understand how APIs work, why they are fundamental to modern software, how to make API calls using common tools, and where you encounter them in your daily digital life. APIs power everything from mobile apps to cloud infrastructure — knowing how they work is essential for any developer.
The Problem APIs Solve
Before APIs, integrating systems meant building custom point-to-point connections. Every time App A wanted data from System B, developers had to write bespoke code that understood System B’s internals. This was brittle, unscalable, and duplicated effort across every integration.
APIs solve this by providing a standardized interface. Instead of reaching into another system’s database directly, you ask its API for what you need. The API abstracts away internal complexity — you don’t care what language the backend is written in or what database it uses. You just send a well-formed request and get a predictable response.
The Restaurant Waiter Analogy
Imagine you are at a restaurant. You (the client) want food but you cannot walk into the kitchen and cook it yourself. You tell your order to the waiter (the API). The waiter takes your request to the kitchen (the server), brings back your food (the response), and handles any special instructions along the way.
- You = Client application (mobile app, website)
- Waiter = API
- Kitchen = Backend server / database
- Menu = API documentation (endpoints, parameters, formats)
- Food = Data or service result
The waiter enforces rules: you can only order items on the menu, you must speak clearly, and you cannot bypass them to grab food directly. The API does the same for software.
How APIs Work (Request → Response)
APIs typically follow a request-response pattern over HTTP:
- A client sends an HTTP request to a specific URL (endpoint).
- The request includes a method (GET, POST, etc.), headers (metadata, auth tokens), and optionally a body (data).
- The server processes the request, applies business logic, and queries databases or other services if needed.
- The server sends back an HTTP response with a status code and a body (usually JSON or XML).
- The client parses the response and uses the data.
Example: REST API Call with cURL
Let’s say we have a public API that returns user data. Here’s what a request looks like:
curl -X GET "https://jsonplaceholder.typicode.com/users/1" \
-H "Accept: application/json"Expected output:
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere@april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874"
}
}The response is structured JSON. Your application can parse this and display the data however it needs.
Common HTTP Methods
| Method | Purpose | Example |
|---|---|---|
| GET | Retrieve data | GET /api/users → list of users |
| POST | Create new resource | POST /api/users → create a user |
| PUT | Replace a resource | PUT /api/users/1 → update user |
| PATCH | Partial update | PATCH /api/users/1 → update email only |
| DELETE | Remove a resource | DELETE /api/users/1 → delete user |
API Key Authentication
Most APIs require authentication to track usage and enforce permissions. A common method is the API key — a unique string sent in the request header:
curl -X GET "https://api.weather.gov/points/39.7456,-97.0892" \
-H "User-Agent: my-app" \
-H "Accept: application/json"The server validates the key on every request. If it’s missing or invalid, the API returns 401 Unauthorized or 403 Forbidden.
Common Use Cases
Payment Gateways — E-commerce sites use Stripe or PayPal APIs to process payments without handling credit card data directly. The API tokenizes sensitive info and returns a confirmation.
Social Login — “Sign in with Google” or “Login with GitHub” uses OAuth 2.0 APIs to verify identity. Your app never sees the user’s password — the identity provider confirms who they are.
Weather Data — Weather apps pull forecasts from services like OpenWeatherMap or NOAA via their APIs. The app sends a zip code and receives temperature, humidity, and forecasts in JSON.
Mapping and Geolocation — Google Maps API lets you embed maps, calculate routes, and search places. Uber, Lyft, and delivery apps all rely on mapping APIs.
Cloud Storage — Dropbox, Google Drive, and AWS S3 all offer APIs to upload, download, and manage files programmatically.
FAQ
Related Terms
What is a REST API — What is GraphQL — What is OAuth 2.0 — What is a JWT
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro