The Language Programs Use to Talk

An API (Application Programming Interface) is a set of rules that allows one program to communicate with another. In web development, we most commonly work with REST APIs.

Core REST Principles

1. Resources

Everything in a REST API is a resource — users, posts, products — each accessible via its own URL:

  • GET /api/users — get all users
  • GET /api/users/42 — get user with ID 42
  • POST /api/users — create a new user

2. HTTP Methods

MethodPurpose
GETRetrieve data (safe, no side effects)
POSTCreate a new resource
PUTReplace an existing resource entirely
PATCHPartially update a resource
DELETERemove a resource

3. HTTP Status Codes

Servers communicate success/failure via status codes:

  • 200 OK — success
  • 201 Created — new resource created
  • 404 Not Found — resource doesn't exist
  • 401 Unauthorized — you need to log in
  • 500 Internal Server Error — something broke on the server
Note

Think of a REST API like a restaurant menu: it has a clear list of what you can order and rules for how to order it.