Skip to the workspace
Pebellslearn by building
Learn the Basics  ›  Lesson

What an API Is

What are APIs 10 minAn API is a published contract that tells other programs what request to send and what response they will get, while hiding how the system works inside.

api design / What an API Is

Explore each scene at your own pace.

01 · The rule

The rule

What an API Is

A phone app shows a list of library books. The phone does not hold the library's catalogue, and it has no business reaching into the library's database. Instead it sends a short, well-formed request to the library's server and gets back exactly the data it asked for. The agreement that makes that exchange possible is an API.

The rule

An API is a published promise: send this, and you will get that.

API stands for Application Programming Interface. It is the part of a program that other programs are allowed to use. Three ideas sit inside the rule:

  • Published: the rules are written down, so a stranger can use the API without reading its source code.
  • Promise: the provider commits to keeping it working. Callers build on it, so breaking it breaks them.
  • Send this, get that: every interaction is a request with a known shape and a response with a known shape.

Throughout this course we design one API: BookNook, a small library service at https://api.booknook.example/v1. It manages books, members and loans. Here is one exchange:

GET /v1/books/42 HTTP/1.1
Host: api.booknook.example

HTTP/1.1 200 OK
Content-Type: application/json

{"id": 42, "title": "The Hobbit", "available": true}

The caller never sees which database, language or server BookNook uses. That hidden part can change freely, as long as the promise holds. This separation is the whole point: the interface stays still while the implementation moves.

APIs are everywhere, not only on the web. A programming language's standard library is an API; so is the set of calls an operating system offers. In this course "API" mostly means a web API: a service that programs reach over the network, usually with HTTP.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.