What is an API? A plain-English guide for beginners
APIs explained with a restaurant example, one small code sample and the status codes you need, plus how to answer the question in an interview.
On this page
"API" appears in almost every developer job description, and in most interviews someone will ask you to explain it. This guide explains what an API is in plain English, with one everyday example and one small piece of code, so you can describe it with confidence even if you have never built one.
The restaurant example
Imagine you are at a restaurant. You do not walk into the kitchen and cook. Instead:
- You read the menu, which lists what you can order.
- You tell the waiter what you want.
- The waiter takes your order to the kitchen and brings back your food.
An API (Application Programming Interface) is the waiter and the menu together. It is an agreed way for one program to ask another program for something, without needing to know how the other program works inside.
When a weather app on your phone shows today's temperature, it did not measure it. It sent a request to a weather service's API and displayed the response.
What a web API request looks like
Most APIs you will meet at work are web APIs: you send a request over the internet to a URL, and you get a response back, usually as JSON (a simple text format for data).
A request has four main parts:
| Part | What it means | Restaurant version |
|---|---|---|
| URL (endpoint) | Where to send the request | Which restaurant |
| Method | What kind of action you want | Order, change order, cancel |
| Headers | Extra details, such as your access key | "I have a reservation" |
| Body | The data you are sending, if any | "One masala dosa, less spicy" |
The four methods you will see most often:
GETreads data ("show me the menu").POSTcreates something new ("place an order").PUTorPATCHupdates something ("change my order").DELETEremoves something ("cancel my order").
A tiny example
Here is how you might ask a hypothetical books API for one book, using Python's popular requests library:
import requests
response = requests.get("https://api.example.com/books/42")
print(response.status_code) # a number such as 200 or 404
print(response.json()) # the data, turned into a Python dictionaryThe server would reply with JSON shaped something like this:
{
"id": 42,
"title": "Clean Code",
"author": "Robert C. Martin",
"available": true
}api.example.com is a placeholder, so this exact code will not return a real book. To practise for real, search for "free public APIs for practice" and pick one that needs no sign-up.
Status codes: the waiter's reply
Every response comes with a status code, a three-digit number that tells you how things went. You only need a few to start:
- 200 OK: it worked, here is your data.
- 201 Created: your new item was created.
- 400 Bad Request: something is wrong with what you sent.
- 401 Unauthorized: you need to log in or send a valid key.
- 404 Not Found: that item does not exist.
- 500 Internal Server Error: the server had a problem; it is not your fault.
A good habit: when something fails, check the status code before anything else. It usually tells you whether to fix your request or wait for the server.
How to explain an API in an interview
Keep it short and concrete:
"An API is a defined way for two programs to talk. One side sends a request to an endpoint, with a method like GET or POST, and the other side sends back a response, usually JSON, with a status code. For example, a weather app calls a weather API to get today's forecast."
Then, if you can, mention something you built that called an API. Even a small project that fetches data and shows it on a page counts. Our list of portfolio projects for freshers has ideas.
Designing your own APIs, including naming, errors and streaming responses, is covered in Hour 07 of Learning Development with AI.
Where to go next
Once calling an API feels natural, read our notes on designing REST APIs for AI features to see how real teams structure them. If you are unsure about AI words like "model" and "token", start with AI terms explained for beginners.