What Is a REST API?
Complete Beginner's Guide
REST APIs power the entire modern web. Every time you check the weather on your phone, post a tweet, or load your Spotify playlist, a REST API is doing the heavy lifting in the background. But what actually IS a REST API, and how does it work?
This guide explains everything from zero — no prior experience needed.
// The Simple Explanation
An API (Application Programming Interface) is a way for two pieces of software to talk to each other. A REST API is a specific type of API that follows a set of rules called REST (Representational State Transfer).
Think of it like a restaurant. You (the client) sit at a table. You don't go into the kitchen — instead, you give your order to a waiter (the API). The waiter takes your request to the kitchen (the server), and brings back your food (the data). The REST API is the waiter.
// How REST APIs Work
The Request-Response Cycle
Every REST API interaction follows the same pattern:
- A client sends an HTTP request to a URL (called an endpoint)
- The server processes the request
- The server sends back an HTTP response with a status code and data
// HTTP Methods (The Verbs)
REST APIs use HTTP methods to indicate what action you want to perform. There are four main ones:
GET — Read Data
Retrieve information. Doesn't change anything on the server. Like asking "show me the menu."
POST — Create Data
Send new data to the server to create a resource. Like submitting a form.
PUT — Update Data
Update an existing resource. Replaces the whole thing (unlike PATCH which only updates part of it).
DELETE — Delete Data
Remove a resource from the server.
// HTTP Status Codes
Every API response includes a status code that tells you what happened:
- 200 OK — Request succeeded
- 201 Created — New resource was created
- 204 No Content — Succeeded but nothing to return
- 400 Bad Request — Your request had an error
- 401 Unauthorized — You need to authenticate
- 403 Forbidden — You don't have permission
- 404 Not Found — Resource doesn't exist
- 500 Internal Server Error — Something broke on the server
// JSON: The Language of REST APIs
Most REST APIs communicate using JSON (JavaScript Object Notation) — a lightweight, human-readable format for structuring data.
JSON uses key-value pairs, arrays, and nested objects. Once you know JSON, you can read any REST API response.
// Your First API Call
Let's make a real API call right now. Open your browser's developer console (F12 → Console) and paste this:
This calls the Coinbase public API and gets the current Bitcoin price. No API key required. You just made your first REST API call.
// Using cURL from the Terminal
cURL is a command-line tool for making HTTP requests. It's the developer's Swiss Army knife for testing APIs:
Add -i to see response headers, -X POST to change the method, and -d '{"key":"value"}' to send a request body.
// REST API Authentication
Most real-world APIs require authentication to know who you are and what you're allowed to do. Common methods:
API Keys
The simplest method. You get a secret key and include it in your request header or URL. Easy to implement but not the most secure.
OAuth 2.0
The standard for "Login with Google/GitHub/Twitter" flows. More complex but very secure. The API gives you a temporary access token after you authenticate.
JWT (JSON Web Tokens)
A self-contained token that encodes user information. Your client sends it with every request. Very common in modern applications.
// REST vs Other API Types
You'll also encounter these API styles:
- GraphQL — You specify exactly what data you want. One endpoint, flexible queries. Used by GitHub, Shopify, Facebook.
- gRPC — High-performance, uses Protocol Buffers instead of JSON. Common in microservices.
- SOAP — Old enterprise standard using XML. Still used in banking and healthcare. Very verbose.
- WebSockets — Persistent two-way connection for real-time data (chat, live prices, etc.).
REST is the most common by far because it's simple, stateless, and works everywhere HTTP works.
// More Dev Guides
Deep dives on REST, sleep optimization, and developer productivity.
explore spunk.rest