Every time you check the weather on your phone, book a flight, or see a map inside a food-delivery app, an API made it happen. Yet when beginners ask how do apis work, the explanations they find are usually either too vague (“it’s a messenger!”) or too technical (walls of HTTP jargon). I remember my own confusion: I knew APIs were important, but nobody could explain what actually happens between my code and the data appearing on screen.
This guide fixes that. We’ll trace a real API request from start to finish, learn the vocabulary (endpoints, requests, responses, keys), work through genuine examples you can run yourself, and demystify REST — the dominant API style. No prior backend knowledge needed. By the end, APIs will feel less like magic and more like ordering from a menu — which, as you’ll see, is exactly the right metaphor.

The Restaurant Analogy (And Where It Breaks)
The classic explanation: an API is like a waiter in a restaurant. You (the app) don’t go into the kitchen (the server) — you tell the waiter (the API) what you want from the menu (the available endpoints), and the waiter brings your food (the data) back.
It’s a decent starting point, but let me sharpen it, because the analogy hides the interesting parts. A better mental model: an API is a contract. The provider promises: “send a request shaped exactly like this, to this address, and I’ll send back data shaped exactly like that.” Your app and their server never meet; they just honor the contract. That contract is what lets a million different apps all use the same weather service without the weather company knowing or caring who they are.
The key insight: APIs let systems cooperate without sharing their internals. The weather company doesn’t give you their database — they give you a narrow, controlled window into it. That window is the API.
How Do APIs Work? A Request’s Journey, Step by Step
Let’s trace what happens when your weather app shows the forecast. Under the hood, it’s roughly this:
- Your app builds a request. It assembles a URL like
https://api.weather.example/forecast?city=Austin&days=3plus some metadata (headers) describing what format it wants. - The request travels the internet to the provider’s server — the same infrastructure that moves web pages around.
- The server processes it. It checks you’re allowed (authentication), reads the parameters (
city=Austin), fetches the relevant data from its database, and formats a response. - The response travels back — usually as JSON, a lightweight text format both humans and machines can read.
- Your app parses the JSON and displays “72°F and sunny” on screen.
The whole round trip often takes under a second. And here’s the part beginners miss: this is the same machinery as loading a web page. When you visit a site, your browser sends an HTTP request and gets HTML back. An API request is the same idea, except a program sends it and gets data (JSON) instead of a web page. If you understand “browser asks server for a page,” you already understand 70% of APIs.
Requests and Responses: The Vocabulary
Every API conversation has the same anatomy. Learn these terms and API documentation stops looking like gibberish:
Endpoint: a specific URL that does one thing. /forecast gives forecasts, /alerts gives weather alerts. The collection of endpoints is the API’s “menu.”
HTTP methods: the verb describing what you want to do. Four cover nearly everything:
– GET — retrieve data (read-only, the most common)
– POST — create something new (submit a form, place an order)
– PUT/PATCH — update something existing
– DELETE — remove something
Parameters: the details of your request. ?city=Austin&days=3 in the URL are query parameters. Some APIs also accept data in the request body (for POST requests).
Headers: metadata about the request — what format you accept, and crucially, your API key (more below).
Status codes: the server’s one-number summary of what happened. 200 means success. 404 means the endpoint doesn’t exist. 401 means your credentials were rejected. 429 means you’re asking too fast (rate limited). 500 means the server messed up. Learning to read status codes is half of debugging APIs.
Response body: the actual data, usually JSON:
{
"city": "Austin",
"forecast": [
{ "day": "Thursday", "high": 72, "condition": "sunny" },
{ "day": "Friday", "high": 68, "condition": "cloudy" }
]
}
If JSON looks unfamiliar, it’s just nested key-value pairs — the same idea as a Python dictionary or JavaScript object. Most languages parse it in one line.
A Real Example You Can Run Right Now
Enough theory — let’s call a real API. This one needs no key and works from your browser’s address bar or terminal. The JSONPlaceholder API is a free fake-data service made for learning:
# Get a sample post (works in any terminal)
curl https://jsonplaceholder.typicode.com/posts/1
You’ll get back:
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit..."
}
You just used an API. In Python, it’s equally simple:
import requests
response = requests.get("https://jsonplaceholder.typicode.com/posts/1")
print(response.status_code) # 200 — success
data = response.json() # parse the JSON into a dictionary
print(data["title"])
And in JavaScript:
const response = await fetch("https://jsonplaceholder.typicode.com/posts/1");
const data = await response.json();
console.log(data.title);
Three lines in either language: send a GET request, check it worked, parse the JSON. That pattern — request, check status, parse — is the skeleton of nearly all API code you’ll ever write. Try changing the URL to /posts, /users/1, /comments?postId=1 and observe how the endpoint shapes the data. Experimenting like this is the fastest way to build intuition.

REST: The Dominant Style, Explained Simply
Most public APIs follow a style called REST (Representational State Transfer). You don’t need the academic definition — in practice, REST means a set of conventions:
- Resources have URLs.
/users/42is user 42./users/42/ordersis their orders. URLs look like nouns, and they’re predictable. - HTTP methods do the verbs.
GET /users/42reads,POST /userscreates,PUT /users/42updates,DELETE /users/42deletes. Same URL, different method, different action. - Statelessness. Each request carries everything the server needs (including your API key). The server doesn’t “remember” you between requests, which is what lets APIs serve millions of users.
When documentation says “RESTful API,” it means the API follows these conventions — which means you can often guess endpoints before reading the docs. That predictability is REST’s whole point.
(You’ll occasionally hear about GraphQL, an alternative where you request exactly the fields you want in a query language. It’s powerful but less common; learn REST first — it’s what the vast majority of jobs and public APIs use.)
Authentication: API Keys and Why They Exist
If APIs are open windows, authentication is the lock. Providers need to know who’s asking — to bill you, to enforce limits, or to protect user data. The common mechanisms:
API keys are the simplest: a long secret string you include with each request, usually in a header. Sign up, get a key, include it. Treat it like a password — never commit it to Git or post it publicly. (This is the same rule as the Git guide’s warning about secrets: leaked keys get abused, and the bill comes to you.)
import requests
headers = {"Authorization": "Bearer YOUR_API_KEY_HERE"}
response = requests.get("https://api.example.com/account", headers=headers)
OAuth is the heavier system behind “Log in with Google” buttons — it lets users grant your app limited access to their accounts without sharing passwords. You’ll meet it when building apps that act on behalf of users; for learning, API keys suffice.
Rate limits deserve a mention: most APIs cap how many requests you can make (e.g., 100 per hour). Exceed it and you get status 429. It’s not personal — it’s how providers keep one greedy app from degrading service for everyone. Cache responses when you can instead of re-requesting.
What APIs Enable: Why Developers Care So Much
Once the mechanics click, the strategic picture opens up. APIs are why small teams can build ambitious products:
- Payments via Stripe’s API — no team needs to become a payments company.
- Maps via mapping APIs — every delivery and ride app.
- AI features via model APIs — chatbots and summarizers without training models.
- Data via thousands of public APIs — weather, finance, sports, government open data.
The pattern: find a hard problem, and someone probably offers it as an API. Modern development is increasingly composition — connecting APIs together — rather than building everything from scratch. Understanding APIs isn’t just a technical skill; it’s how you scope what’s possible.
This is also why APIs appear everywhere in job descriptions. Frontend developers consume them constantly (every dynamic page is API calls behind the scenes). Backend developers build them. Data folks pull from them — my Python for data analysis guide uses APIs as a data source, and SQL basics covers where that data often ends up stored.
Versioning: Why APIs Have v1, v2, v3
If you browse API docs, you’ll notice version numbers in URLs: /v1/users, /v2/users. This exists because APIs are contracts — and contracts can’t change unilaterally without breaking everyone who depends on them. When a provider needs to rename a field or change behavior, they ship a new version alongside the old one rather than breaking existing apps overnight.
For you as a consumer, this means two habits: always use an explicitly versioned endpoint (unversioned URLs can change under you), and watch for deprecation notices — providers announce shutdowns months ahead, but only in changelogs and emails, not in your code. Pinning your integration to /v2/ and subscribing to the provider’s developer updates takes five minutes and prevents the special misery of waking up to a broken app because an API you forgot about shipped v3.
It also explains something about API design philosophy: good providers treat breaking changes as a serious event, with migration guides and long sunset periods. When evaluating an API to build on, check its versioning history — a provider that versions carefully is a provider you can trust with your product’s foundation.
Reading API Documentation Without Panic
Documentation is where beginners bounce off. Here’s how to read it systematically:
- Find the authentication section first. Nothing works until this is right. Get your key, figure out where it goes (header? query param?).
- Find one simple GET endpoint and get it working. Don’t start with the complex stuff — one successful call builds the mental model.
- Note the base URL, required parameters, and response format. Docs list these per endpoint; they’re the contract.
- Check the error section. Knowing what
400vs401vs422means for this API saves hours of guessing. - Look for a try-it console. Many docs let you send test requests from the browser — the fastest possible feedback loop.
When something fails, debug in order: Is the URL right? Is the method right? Is my key included and valid? Are required parameters present? What does the status code say? Nine times out of ten, the answer is in that checklist.

Webhooks and Polling: When the Server Calls You
So far we’ve only seen one direction: your app asks, the server answers. But what about events — a payment completing, a message arriving, code being pushed? Your app can’t know when something happens unless it asks repeatedly… or unless the server calls you. Both patterns are everywhere.
Polling is the simple approach: ask on a schedule. “Any new messages?” every 30 seconds. It’s easy to implement — just a setInterval around your GET request — and it works with any API. The downsides are obvious: most requests return “nothing new,” wasting bandwidth and battery, and there’s always a delay between the event and your next check. For low-stakes updates (refreshing a dashboard every few minutes), polling is perfectly fine and often the pragmatic choice.
// Poll for new notifications every 30 seconds
setInterval(async () => {
const res = await fetch("https://api.example.com/notifications?since=" + lastCheck);
const updates = await res.json();
if (updates.length > 0) showBadge(updates.length);
lastCheck = Date.now();
}, 30000);
Webhooks flip the direction: you give the provider a URL on your server, and they POST to it when events happen. Stripe uses webhooks to tell your app “payment succeeded”; GitHub uses them to notify your CI system “code was pushed.” Instead of asking repeatedly, you get tapped on the shoulder exactly when something happens.
Setting one up looks like this conceptually:
from flask import Flask, request
app = Flask(__name__)
@app.route("/webhooks/payments", methods=["POST"])
def handle_payment():
event = request.json
if event["type"] == "payment.succeeded":
fulfill_order(event["data"]["order_id"])
return {"received": True}, 200
You register https://yourapp.com/webhooks/payments in the provider’s dashboard, and they start sending events. Two things matter enormously with webhooks: verify the signature (providers sign their requests with a secret so you know they’re genuine — never trust an unsigned webhook), and respond fast (acknowledge receipt immediately, do the slow work afterwards; providers retry if you’re slow, which can double-process events).
How to choose: polling when updates are infrequent, delays are tolerable, and you control only the client side. Webhooks when events are time-sensitive (payments, messages, alerts) and you run a server that can receive them. Many real systems use both — webhooks for the critical path, polling as a fallback safety net in case a webhook delivery fails.
There’s a third option you’ll hear about — WebSockets — which keep a persistent two-way connection open for true real-time communication (chat apps, live games, collaborative editing). They’re more complex to run than either polling or webhooks, so reach for them only when sub-second interactivity is the actual requirement.
Key Takeaways
- How do APIs work? Your app sends an HTTP request to an endpoint; the server processes it and returns data (usually JSON). It’s the same machinery as loading a web page.
- Learn the vocabulary: endpoints, methods (GET/POST/PUT/DELETE), parameters, headers, status codes.
- The request → check status → parse JSON pattern covers nearly all API code.
- REST conventions (resource URLs + HTTP verbs + statelessness) make APIs predictable.
- API keys authenticate you — guard them like passwords and respect rate limits.
- Reading docs systematically (auth first, one simple call, then errors) beats random trial and error.
Frequently Asked Questions
What is an API in simple terms?
An API (Application Programming Interface) is a contract that lets one piece of software request data or actions from another. Your app sends a structured request to a URL (the endpoint), and the server sends back structured data (usually JSON). It’s how apps use weather data, maps, payments, and AI without building those systems themselves.
Do I need to know how to code to understand APIs?
To understand the concept, no — the restaurant/menu analogy plus the request-and-response idea is enough. To use APIs, you need basic coding in any language (Python’s requests or JavaScript’s fetch will do) — but only a few lines’ worth.
What’s the difference between an API and a web service?
They overlap heavily. “Web service” is the broader term for software available over the network; “API” is the specific interface you program against. In everyday developer speech, a “REST API” and a “web service” usually refer to the same thing.
Are APIs free to use?
Many offer free tiers with rate limits — enough for learning and small projects. Heavy or commercial use usually requires payment. Always check an API’s pricing and terms before building something that depends on it, since free tiers can change.
What does “REST API” mean?
REST is a set of conventions for designing APIs: resources identified by URLs (/users/42), HTTP methods as verbs (GET reads, POST creates), and stateless requests. A “REST API” follows these conventions, which makes its endpoints predictable even before you read the docs.
APIs stop being mysterious the moment you make your first real request. Run the curl example above, change the endpoint, watch the JSON change — that ten-minute experiment teaches more than any analogy. From there, every app you use becomes legible: behind each screen is a series of requests, each answered by a server honoring its contract. And now you know exactly how the conversation works — from the request your app builds to the JSON that comes back. The next time someone asks you how do apis work, you will have something better than the waiter analogy: the full journey, step by step.
