What is an API?
An API is a way for one program to ask another program for something. Here's how APIs work, a real request with fetch, what a REST API is, and the browser APIs JavaScript uses every day.

At a restaurant, you don't walk into the kitchen and cook your own meal. You read the menu, tell the waiter what you'd like, and the waiter brings it to your table. You never see how the kitchen works, and you don't need to.
An API is a way for one program to ask another program for something, using a fixed set of requests the other program has agreed to answer. The list of requests is the menu. The API is the waiter that carries your order in and the answer back out. On the web, it's usually an address on a server that your code can ask for data, like a user's profile.
What does API stand for?
API stands for application programming interface. Each word tells you something:
- Application means any program, like a weather service, a bank's server, or your browser.
- Programming means code uses it, not a person clicking buttons.
- Interface means the place where two things meet. A screen is the interface between you and an app. An API is the interface between two programs.
So an API is the part of a program that other programs talk to. The program can change a lot on the inside. As long as its API stays the same, everything that uses it keeps working.
How does an API work?
Every API conversation has two sides. The client is the program that asks. The server is the program that answers. On the web, the client is often your browser, and the server is a computer somewhere else that holds the data.
The client sends a request. A request says where to go and what to do:
- A URL is the address of the thing you want, like
https://api.github.com/users/octocat. - A method is a word that says what to do.
GETmeans "give me this", andPOSTmeans "here's something new, please save it". - A body is data you send along, like the text of a new comment. Not every request has one.
The server sends back a response. It starts with a status code, a number that says how it went, like 200 for success or 404 for "not found". HTTP status codes explains the ones you'll meet. The response usually has a body too, with the data you asked for.

The rules for this back-and-forth are called HTTP, short for HyperText Transfer Protocol. Your browser uses the same rules to load every web page.
What does a real API request look like?
GitHub has a public API that anyone can call. Here's how to ask it for one user's profile with fetch, the function browsers give JavaScript for making requests.
const response = await fetch("https://api.github.com/users/octocat");
const user = await response.json();
console.log(user.name); // "The Octocat"
The first line sends a GET request to GitHub's server and waits for the response. The second line reads the body and turns it into a JavaScript object. The third line prints one of its fields. You can paste all three lines into your browser's console to try it.
Here's part of what GitHub sends back:
{
"login": "octocat",
"name": "The Octocat",
"html_url": "https://github.com/octocat",
"type": "User"
}
This format is called JSON, short for JavaScript Object Notation. It's plain text shaped like a JavaScript object, and it's the usual format for web APIs. The JSON lesson shows how to read and write it. The fetch lesson covers requests in depth, and async and await explains the waiting.
What are some examples of APIs?
You use APIs every day without seeing them:
- A weather app doesn't measure the weather. It asks a weather service's API for the forecast and shows the answer.
- A "Sign in with Google" button asks Google to confirm who you are. The site never sees your Google password.
- A shop's checkout sends your card details to a payment company's API. The API answers whether the payment went through.
- A map on a café's website is drawn with a maps company's API.
In each case, one program asks another program for something. Neither one needs to know how the other works inside.
What is an API endpoint?
An endpoint is one address in an API that does one job. If the API is the whole menu, an endpoint is one dish on it. https://api.github.com/users/octocat is one endpoint of GitHub's API. Others list a user's projects or search for code.
An API's documentation is the menu written out in full. It lists every endpoint, what to send, and what you'll get back. Reading it is the first step whenever you use a new API.
What is a REST API?
REST is a common style for designing web APIs. The name stands for representational state transfer, but the idea is simpler than the name. Every thing the API knows about, like a product or an order, gets its own URL. Then HTTP methods say what to do with it.
Here's how a REST API for a shop might look:
| Request | What it does |
|---|---|
GET /products |
Lists all the products |
GET /products/42 |
Gets product 42 |
POST /products |
Adds a new product |
PATCH /products/42 |
Changes part of product 42 |
DELETE /products/42 |
Removes product 42 |
An API built this way is called RESTful. Because RESTful APIs share the same pattern, once you've used one, you can guess how the next one works. REST for frontends goes deeper into methods, status codes, and errors.
What are browser APIs?
"API" has a second meaning that confuses many beginners. It also means the features a browser builds in for JavaScript to use. There's no server and no URL. They're functions and objects that are already there when your page loads.
const heading = document.querySelector("h1");
heading.textContent = "Hello!";
localStorage.setItem("theme", "dark");
The first two lines use the DOM API, which lets JavaScript find and change things on the page. The last line uses the Web Storage API to save a setting in the browser, so it's still there next visit. Even fetch is a browser API. It's the one browsers give you for calling web APIs.
Other browser APIs copy text to the clipboard, find the device's location, or play sound. MDN's Web API reference lists them all. The browser environment explains where they come from, and device APIs puts the clipboard and location ones to work.
What mistakes do beginners make with APIs?
- Expecting
fetchto fail on errors. It only fails when the request can't happen at all, like when you're offline. A404still counts as a response. Checkresponse.okbefore you use the data, as this interview question shows. - Forgetting the second
await. Reading the body withresponse.json()takes time too, so it needs its ownawait. - Putting a secret key in frontend code. Many APIs ask for a key, a password-like string that identifies you. Anyone who visits your page can read its JavaScript, so secret keys belong on a server.
- Being surprised by CORS errors. A browser won't let your page read a response from another origin unless that server allows it. An origin is a site's protocol, domain, and port together. The CORS lesson explains the rules.
Where should you go next?
Start with the fetch lesson. It makes real requests in your browser and handles errors properly. If await still feels new, read promises first. Then learn what each response number means in HTTP status codes. If you're new to JavaScript itself, the JavaScript course starts from the very first line.


