Skip to main content

Web and APIs

What is an API?

Definition

An API is a defined set of rules that lets one program request data or actions from another without knowing how that other program works inside.

Also known as: Application Programming Interface

API in more detail

An API — application programming interface — is a contract. One side publishes what it can do, what shape the request must take, and what it will send back; the other side writes code against that description and never has to know what happens behind it. The hiding is the point: a payments service can be rewritten in a different language over a weekend and every caller keeps working, because the contract did not move.

The word covers two related things. A library API is the set of functions, classes and types a package exposes to code running in the same process. A web API is reached across the network, almost always over HTTP, and is what most people mean today: you send a request to a URL and get JSON back. REST and GraphQL are two styles of web API, and a webhook is the same idea pointed the other way, with the service calling you.

Because callers depend on the contract, changing an API is the hard part of running one. Adding an optional field is safe; renaming a field, removing one, or tightening validation breaks whoever relied on the old behaviour. That is why public APIs carry a version in the path, deprecate long before they delete, and document their error responses as carefully as their successful ones.

API example

GET https://api.example.com/v1/orders/8842
Authorization: Bearer sk_live_xxxxxxxx

200 OK
Content-Type: application/json

{
  "id": "8842",
  "status": "shipped",
  "total_cents": 4900,
  "currency": "usd"
}

API — common questions

What does API stand for?
Application programming interface. The name is literal: it is the interface one piece of software presents to the programs that want to use it, as opposed to the user interface it presents to people.
Is an API the same thing as a website?
No. A website returns HTML meant to be rendered for a human; an API returns structured data such as JSON meant to be parsed by another program. The same server often serves both from the same database.
Do I need an API key to use an API?
Only when the provider requires one. Public APIs such as many open-data endpoints accept anonymous requests, while anything that costs money, exposes private data or needs rate limiting per customer will issue a key or token you send with each request.

Keep reading

Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.

Browse the A-Z glossary