What Is an API? A Beginner's Guide
You've probably heard the term API thrown around constantly in tech conversations, often as if everyone already knows what it means. The concept is actually pretty simple: an API is just a defined way for two pieces of software to talk to each other.
The Restaurant Menu Analogy
Think of an API like a menu at a restaurant. You don't walk into the kitchen and cook your own food, and you don't need to know how the kitchen works internally. You look at the menu, order something by name, and the kitchen hands you back a finished dish. The menu is the interface, a fixed set of things you're allowed to ask for, and how you ask for them.
An API works the same way for software. It's a defined set of requests one program can make to another, without needing to know anything about how that other program works internally.
Where APIs Show Up
Web APIs. When a weather app shows you today's forecast, it isn't calculating meteorology itself. It's sending a request to a weather service's API and displaying whatever data comes back.
Library and framework APIs. When you call a function like fetch() in JavaScript or len() in Python, you're using an API too, just one that's part of the language or a library rather than a separate service over the internet.
Operating system APIs. Apps request things like file access or notifications from your operating system through defined APIs, without needing to know how the OS manages hardware underneath.
What a REST API Request Actually Looks Like
Most APIs you'll interact with as a web developer are REST APIs, which organize everything around resources (like a specific user, or a specific post) and use standard HTTP methods to act on them:
GET /users/42 → retrieve user with ID 42
POST /users → create a new user
PUT /users/42 → update user 42's full data
DELETE /users/42 → delete user 42
Here's what a simple request to fetch data from an API looks like in JavaScript:
fetch("https://api.example.com/users/42")
.then(response => response.json())
.then(data => console.log(data));
This sends a GET request to the endpoint /users/42, and the API responds with data, usually formatted as JSON, that your code can then use.
Endpoints, Requests, and Responses
Endpoint. A specific URL an API exposes for a specific purpose, like /users or /products/5.
Request. What your code sends to the API, including the HTTP method, the endpoint, and sometimes a body containing data.
Response. What the API sends back, typically including a status code (like 200 for success or 404 for not found) and a body containing the requested data.
Why APIs Matter So Much
APIs are what let modern software be built out of pieces instead of from scratch every time. A payment app doesn't need to build its own banking infrastructure, it calls a payment API. A website doesn't need to build its own maps, it calls a mapping API. This is the foundation that makes the modern web modular and interconnected.
Where to Go From Here
APIs make the most sense once you actually call one. Try fetching data from a free public API and displaying it on a simple webpage, paying attention to the request you send and the JSON response you get back.
If you want to practice working with APIs hands-on with guided lessons and a live code playground, CodeFacility's JavaScript courses cover fetch requests, JSON, and working with real APIs step by step and completely free.