API
Application Programming Interface
In short
An API is a set of rules that lets one piece of software request data or actions from another in a predictable, documented way.
What is an API?
An API is a contract: it describes which operations a piece of software offers to others and exactly how to call them. As long as the caller follows those rules, it can use the functionality without knowing anything about how it works inside.
A common analogy is a waiter in a restaurant. You don't walk into the kitchen; you give your order to the waiter, who brings back the result. On the web, the order is usually an HTTP request and the result is usually data in JSON format.
APIs are not limited to web services. The functions an operating system exposes for reading files, or the public methods of a library, are APIs too.
How it works
Your code sends a request
It calls an address the API documents and says what it wants.
GET /v1/weather?city=ParisThe API checks it
It checks your key and that the request follows its rules.
X-API-Key: 4f9a…The provider does the work
Behind the API, the provider's own code and databases find the answer. You never see them.
You get the answer
It comes back in the agreed format, usually JSON, with a status code that says how it went.
200 OK {"temp": 18}
Often misunderstood
You might think: An API is a website or a server.
In fact: An API is a contract: the requests a piece of software accepts and the answers it gives back. It is often a web service, but a library or an operating system offers an API to your code too.
At a glance
Key takeaways
- An API defines how two pieces of software communicate.
- Callers don't need to know the internal implementation.
- Web APIs usually work over HTTP and return JSON.
- Libraries and operating systems expose APIs too, not just web services.
Example
// Ask the API for a user's details
const response = await fetch("https://api.example.com/users/42");
const user = await response.json();
console.log(user.name);Readers ask
Is an API the same as a REST API?
No. API is the general concept; a REST API is one style of API built on HTTP that follows REST principles.
What is an API key?
An API key is a secret value sent with requests so the API can identify the caller and control or limit access.
See also
- API vs SDKAn API is the set of requests or functions a service offers, while an SDK is a toolkit, usually built on that API, that makes it easier to use from a language.
- API vs WebhookWith an API, your app sends a request whenever it wants data; with a webhook, another service sends a request to your URL as soon as an event happens.
- MCP vs APIAn API is any interface programs call to use a service; MCP is an open standard for connecting AI apps to tools and data, and its servers often wrap APIs.
- REST APIBackend & APIs, p. 42A REST API is a web API that exposes data as resources identified by URLs and lets clients read or change them using standard HTTP methods.
- GraphQLBackend & APIs, p. 22GraphQL is a query language and runtime for APIs that lets clients request exactly the data they need, often from a single endpoint in a single request.
- EndpointBackend & APIs, p. 15An endpoint is a specific URL, combined with an HTTP method, where an API receives requests and returns responses for one particular resource or action.
- JSONBackend & APIs, p. 28JSON is a lightweight, text-based format for storing and exchanging structured data as key-value pairs and lists, readable by both humans and machines.
- HTTPWeb Development, p. 23HTTP is the protocol that browsers, apps, and servers use to exchange web pages and data through a simple cycle of requests and responses.
- API GatewayBackend & APIs, p. 3An API gateway is a server that sits in front of a group of backend services and acts as the single entry point that receives, checks, and routes API requests.
- SDKProgramming Fundamentals, p. 57An SDK (software development kit) is a package of tools, libraries, documentation and examples for building software for a particular platform or service.
Free · once a week
Software and AI, explained once a week
The week's software and AI news with every term explained, plus a term to learn and a quick quiz. A two-minute read.
See this week's issueAbout this page
Page history
Added "How it works": an API call from request to answer, and what an API really is.
Changes that altered what this page says. Typo fixes are not listed.
Spotted a mistake or something missing on this page?Suggest an edit
How pages are made