A REST API is an architectural style for building web APIs using standard HTTP methods (GET, POST, PUT, DELETE) and URLs to represent resources. REST is stateless, meaning each request contains all the information needed to process it.

How REST API Works

REST stands for Representational State Transfer, coined by Roy Fielding in 2000. The key idea: everything is a resource with a unique URL. /users is the users collection, /users/42 is a specific user. HTTP verbs define what you do with the resource.

REST APIs are stateless — the server doesn't remember previous requests. Every request must include authentication tokens, pagination parameters, and any context. This makes REST APIs horizontally scalable because any server can handle any request.

Most REST APIs return JSON, use HTTP status codes for errors, and follow conventions like pluralized resource names. A well-designed REST API is intuitive: GET /posts returns posts, POST /posts creates one, PUT /posts/1 updates it, DELETE /posts/1 removes it.

Why Developers Use REST API

REST is the default choice for web APIs. It powers the backends of most web and mobile apps. If you're building a CRUD application, a REST API with Express, FastAPI, Django REST Framework, or Spring Boot is the standard approach.

Key Concepts

  • Resources — Everything is a resource identified by a URL — /api/products, /api/orders/123
  • Stateless — Each request is independent. No server-side sessions. Auth tokens go in every request.
  • HTTP Verbs — GET reads, POST creates, PUT/PATCH updates, DELETE removes — map directly to CRUD operations
  • JSON Responses — REST APIs almost universally use JSON for request and response bodies
  • Status Codes — 2xx success, 3xx redirect, 4xx client error, 5xx server error — standard HTTP semantics
  • HATEOAS — Hypermedia links in responses that tell clients what actions are available next — rarely implemented in practice

Building a REST API with Express

javascript
const express = require('express');
const app = express();
app.use(express.json());

let todos = [{ id: 1, text: 'Learn REST', done: false }];

app.get('/api/todos', (req, res) => res.json(todos));
app.post('/api/todos', (req, res) => {
  const todo = { id: Date.now(), ...req.body, done: false };
  todos.push(todo);
  res.status(201).json(todo);
});

app.listen(3000);

Frequently Asked Questions

What is the difference between REST and GraphQL?

REST uses multiple endpoints (one per resource) and returns fixed data shapes. GraphQL uses a single endpoint where clients specify exactly what fields they need. REST is simpler; GraphQL is more flexible for complex data requirements.

Is REST the same as HTTP?

No. REST is an architectural style that uses HTTP as its transport protocol. HTTP is the protocol; REST is a set of conventions on top of HTTP for structuring APIs.

When should I not use REST?

Consider alternatives when you need real-time updates (use WebSocket), highly flexible queries (use GraphQL), or high-performance service-to-service calls (use gRPC).