API
In one line
An API (Application Programming Interface) is a set of rules that defines how different software components communicate with each other.
In simple words
An API is a contract between two pieces of software. It defines what functions you can call, what arguments they take, and what they return — without revealing how they work internally. You use APIs every day without thinking about it.
For example, the JavaScript console.log() is an API: you call it with a string, it prints to the console. You do not know (or need to know) how it actually writes to the terminal. Web APIs like fetch() let you make HTTP requests without understanding TCP/IP.
APIs come in many forms: language standard libraries (built-in functions), web APIs (REST endpoints you call over HTTP), library APIs (functions from npm/pip packages), and operating system APIs. The key idea is always the same: a defined interface that hides implementation details.
Example
// Using a web API (fetch)
async function getUser(id) {
const response = await fetch(`/api/users/${id}`);
const user = await response.json();
return user;
}
// The fetch API hides all the HTTP/TCP complexity
// You just call it with a URL and get data backfetch() is an API: you pass a URL, it returns a response. All the networking complexity is hidden behind this simple interface.
Related terms
Related Resources
Related Lessons
- Modules and Imports
Learn about modules and APIs.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.