What you'll learn
- Quick answer
- What Is an API? The Short Version
- The Waiter Analogy: APIs in Real Life
- Web APIs and REST: The Kind You'll Meet First
- How a Request and Response Actually Work
- What Is JSON? The Language APIs Speak
- A Real Example: Calling an API with fetch()
- APIs You Already Use Every Day
- Why APIs Matter for Developers
- How to Start Learning APIs
- FAQ
Quick Answer
An API (Application Programming Interface) is a set of rules that lets two pieces of software talk to each other and share data. Think of it like a waiter in a restaurant: you (one program) tell the waiter what you want, the waiter carries your order to the kitchen (another program), and brings the food back. On the web, your app sends a request to an API endpoint and gets a response — usually as JSON data — which it can then display or use. APIs let developers reuse powerful services like maps, payments, and weather instead of building them from scratch.
What Is an API? The Short Version
If you have spent any time around programming, you have probably heard the word API thrown around a lot. So what is an API, really? API stands for Application Programming Interface, and in plain words it is a set of rules that lets two pieces of software talk to each other and share data or features.
Here is the key idea: you do not need to know how the other program works on the inside. You only need to know how to ask it for something and what you will get back. That is the whole point of an interface — it hides the messy details and gives you a simple, agreed-upon way to make a request.
APIs are everywhere. When you check the weather on your phone, log in with Google, pay with UPI, or see a live map inside a food-delivery app, an API is quietly doing the work behind the scenes. In this guide we will build the idea up slowly — from a simple real-world analogy to a small piece of working JavaScript you can run yourself.
The Waiter Analogy: APIs in Real Life
The clearest way to understand an API is to picture a restaurant.
You sit at a table with a menu. You do not walk into the kitchen and cook the food yourself, and you do not need to know how the kitchen is organised. Instead, you tell the waiter what you want. The waiter carries your order to the kitchen, the kitchen prepares the dish, and the waiter brings it back to your table.
In this picture:
- You are the client — the app or program that needs something.
- The kitchen is the server — the system that has the data or does the real work.
- The waiter is the API — the messenger that carries your request and brings back the response.
- The menu is the API's documentation — the list of things you are allowed to ask for.
Notice what the API gives you: a clear, limited menu of requests, without ever exposing the kitchen. You cannot order something that is not on the menu — and that is a good thing. It keeps the whole system predictable and safe. Software APIs behave in exactly the same way.
Web APIs and REST: The Kind You'll Meet First
APIs come in several flavours, but the ones you will meet first as a beginner are web APIs — APIs you talk to over the internet using the same technology that loads web pages (HTTP).
Most modern web APIs follow a style called REST (Representational State Transfer). You do not need to memorise the fancy name. What matters is the simple pattern REST gives us: every piece of data lives at a web address called an endpoint, and you interact with it by sending an HTTP request to that address.
For example, a weather service might have an endpoint like https://api.example.com/weather?city=Delhi. Your program sends a request to that URL, and the server sends back the weather data. That is a REST API in action — clean, predictable web addresses that return raw data instead of a full web page.
How a Request and Response Actually Work
The request: methods and endpoints
Every API call has two sides: the request you send and the response you get back. A request always includes the endpoint (the URL) plus an HTTP method that says what you want to do. The two you will use most are:
- GET — read or fetch data. "Give me the weather for Delhi."
- POST — send or create data. "Here is a new order, please save it."
There are a few others — PUT and PATCH to update, DELETE to remove — but GET and POST cover most of what beginners do.
The response: status codes
When the server answers, it includes a status code: a three-digit number that tells you how the request went. You have already met the most famous one — 404 Not Found. Here are the codes worth knowing early:
| Status code | What it means |
|---|---|
200 OK | Success — your data is in the response. |
201 Created | Success, and something new was saved (common after a POST). |
400 Bad Request | Your request was wrong or missing something. |
401 Unauthorized | You need to log in or send a valid API key. |
404 Not Found | That endpoint or item does not exist. |
500 Server Error | Something broke on the server's side, not yours. |
A quick rule of thumb: codes in the 200s mean success, 400s mean the problem is on your side (the request you sent), and 500s mean the problem is on the server's side.
What Is JSON? The Language APIs Speak
When an API sends data back, it needs a format both sides understand. The most common one by far is JSON (JavaScript Object Notation). JSON is just text, arranged as key-value pairs, that is easy for humans to read and easy for programs to parse.
Here is what a weather response might look like in JSON:
{
"city": "Delhi",
"temperature": 34,
"unit": "celsius",
"conditions": "Clear sky"
}If you have seen a JavaScript object before, this will look familiar — and that is no coincidence. Each item has a key (like "temperature") and a value (like 34). Values can be text, numbers, true/false, lists, or even other nested objects. Once your program receives this text, it converts it into data it can use — for example, reading data.temperature to show 34 on the screen.
Despite the name, JSON is not tied to JavaScript. Python, Java, PHP, and almost every language can read and write it, which is exactly why it became the shared language of web APIs.
A Real Example: Calling an API with fetch()
Let's put it all together with a small, real example. Modern browsers have a built-in function called fetch() that sends an HTTP request for you. Below we call a free, open weather API (no sign-up or key needed) and print the current temperature in Delhi.
fetch("https://api.open-meteo.com/v1/forecast?latitude=28.61&longitude=77.21¤t_weather=true")
.then((response) => response.json())
.then((data) => {
console.log("Temperature now:", data.current_weather.temperature, "C");
})
.catch((error) => {
console.log("Something went wrong:", error);
});Read it top to bottom like a sentence: fetch this endpoint, turn the response into JSON, then use the data. Here is what each step does:
fetch(...)sends a GET request to the endpoint (the URL, with the location and options after the?)..then((response) => response.json())takes the raw response and parses the JSON text into a usable object.- The second
.then(...)receives that object asdataand reads one value out of it. .catch(...)runs only if something fails — a dropped network or a bad request — so your app does not crash.
You can paste this straight into your browser's developer console (press F12, open the Console tab) and run it right now. Because API calls take time — the request has to travel across the internet — this code is asynchronous: the .then() parts run later, once the data arrives. Learning to handle that timing is a core skill, and our free JavaScript course covers fetch, promises, and async/await step by step.
APIs You Already Use Every Day
Once you know the pattern, you start seeing APIs everywhere. A few you have almost certainly used:
- Weather APIs — weather widgets do not measure the temperature themselves. They ask a weather API and display whatever comes back, just like the example above.
- Payment APIs — when you pay on an Indian site with UPI, a card, or a wallet, the site does not handle your bank details directly. It sends the payment to a provider like Razorpay or Stripe through their API, which does the risky, regulated work securely and returns a simple "success" or "failed" response.
- Maps APIs — the live map inside a ride-hailing or food-delivery app is usually the Google Maps API, embedded through a few API calls rather than built from scratch.
The pattern is always the same: instead of building a hard, specialised feature yourself, you send a request to a service that has already solved it, and use the response it sends back.
Why APIs Matter for Developers
APIs are one of the most important ideas in modern software, and here is why they matter so much for you as a developer:
- You don't reinvent the wheel. Building secure payments or accurate maps from zero would take years. An API lets you add these features in an afternoon.
- Systems stay separate and safe. Because the API only exposes a fixed menu, a payment company can rebuild its entire kitchen without breaking your app, and you never touch their sensitive internals.
- Your own apps will provide APIs too. When you build a backend, you are usually building an API that your website or mobile app talks to. This front-end / back-end split is how nearly all modern apps are structured.
In other words, understanding APIs is not an advanced extra — it is the everyday glue that connects the software world. Almost every real project you build will either use an API, provide one, or both.
How to Start Learning APIs
You do not need to master everything at once. Here is a sensible order for actually learning APIs by doing:
- Get comfortable with JavaScript basics — variables, functions, and objects — so JSON and
fetch()feel natural. - Practise calling public APIs with
fetch(). Free, keyless ones like Open-Meteo (weather) are perfect for experimenting without any setup. - Learn to build your own API. On the back end, Node.js with a library called Express is the most beginner-friendly way to create your own endpoints that respond to GET and POST requests.
If you want a guided path, start with our free JavaScript course to nail the fundamentals, then move on to the free Node.js course, where you will build a real REST API of your own from scratch. Learn the request-and-response pattern once, and it will serve you in every language and every framework you touch afterwards.
Frequently Asked Questions
Do I need to know how to code to use an API?
To actually call an API inside a program, yes — you need some basic coding, usually JavaScript or Python. But the idea is simple, and you can explore many public APIs just by pasting their URL into your browser to see the JSON they return.
Are all APIs free?
No. Some are completely free, some are free up to a limit and then charge, and some need a paid plan from the start. Free, keyless APIs like Open-Meteo are great for learning, while services such as maps and payments usually require an account and often a paid plan at scale.
What is an API key?
An API key is a unique string of characters that identifies you to the API, a bit like a membership card. Many services ask you to sign up, get a key, and send it with each request so they can control access and track usage. Keep your keys private — never post them in public code.
What is the difference between REST and an API?
"API" is the general idea of software talking to software. "REST" is one popular style of building web APIs, based on endpoints (URLs) and HTTP methods like GET and POST. Most web APIs you meet today are REST APIs, but REST is just one way to design an API among several.
Which language should I learn to build APIs?
For beginners, JavaScript with Node.js is one of the easiest and most popular choices, because you use the same language on both the front end and the back end. Python (with Flask or Django) and Java (with Spring) are also widely used. The request-and-response concepts are the same across all of them.
