Skip to main content
REST (Representational State Transfer) is the most widely adopted architectural style for web APIs. Understanding its principles is essential not just for building APIs, but for explaining your design decisions. This page covers every REST concept you need: the six constraints, HTTP methods, status codes, URL design rules, and how to put it all into practice with Express.

What Is REST?

REST is an architectural style introduced by Roy Fielding in 2000. It is a set of guidelines for designing networked applications over HTTP. REST is not a protocol, library, or framework. In REST, everything is a resource (a user, order, product) identified by a unique URL. Clients interact with resources using standard HTTP methods.

The 6 REST Constraints

1

Client-Server

Client (handles UI) and server (handles data/logic) are separate systems communicating over HTTP. Each can evolve independently.
2

Stateless

The server stores NO client session state between requests. Every request must contain all information needed. Authentication tokens, not server sessions.
3

Cacheable

Responses must indicate whether they can be cached. Caching reduces server load for repeated requests.
4

Uniform Interface

All resources use consistent URL patterns and HTTP methods. The API is predictable regardless of resource type.
5

Layered System

The client cannot tell if it is connected to the actual server or an intermediary (load balancer, cache, gateway). Layers are transparent.
6

Code on Demand (optional)

Servers can send executable code to clients (e.g., JavaScript). Rarely used. The only optional constraint.
Stateless is the most exam-relevant constraint. It means the server never stores session data in memory. Each request from a client must include auth credentials (like a JWT token). This enables horizontal scaling.

HTTP Methods

Idempotent = calling the same operation multiple times gives the same result. Safe = the operation does not change server state.
Exam tip: POST is the only non-idempotent method. Calling POST /users twice creates two users. Calling DELETE /users/1 twice deletes once then returns 404 (same end state).

HTTP Status Codes

Memorize these. Exams test status code knowledge heavily.
401 vs 403 is a classic exam question. 401 = “You are not logged in.” 403 = “You are logged in, but you don’t have permission.” Never mix them up.

URL Design Best Practices

1

Use nouns, not verbs

The HTTP method is the verb. The URL is the noun.
2

Use plural resource names

3

Use nesting for relationships

4

Use lowercase with hyphens

Request and Response Anatomy

HTTP Request

HTTP Response

REST vs SOAP vs GraphQL

Full /users Route Example in Express

Mount in app.js:

Testing with Postman

1

Create a request

Open Postman, click New > HTTP Request.
2

Set method and URL

3

Add Content-Type header

Headers tab: Content-Type: application/json
4

Add body

Body tab > raw > JSON: {"name": "Alice", "email": "alice@test.com"}
5

Send and inspect

Click Send. Check the status code and response body.

Key Terms