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.
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.
Often compared
See also
- REST APIBackend & APIs, p. 38A 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. 19GraphQL 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. 12An 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. 25JSON 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. 19HTTP 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. 51An SDK (software development kit) is a package of tools, libraries, documentation and examples for building software for a particular platform or service.
Spotted a mistake or something missing on this page?Suggest an edit