Architecture Intermediate

REST

Representational State Transfer. An architectural style for designing web APIs that uses standard HTTP methods and resource principles to create simple, scalable interfaces.

Pronunciation

/rɛst/
"rest"

What is it

REST stands for Representational State Transfer. It’s a set of principles for designing web APIs that uses the HTTP protocol so that any client (web, mobile, other servers) can communicate with the server predictably.

An API following these principles is called RESTful or a REST API.

The 6 REST Principles

PrincipleDescription
StatelessEach request contains all necessary information — the server doesn’t “remember” previous requests
Client-ServerClient and server are independent — the client doesn’t know how the backend works
Uniform InterfaceResources with consistent URLs and standard HTTP methods
CacheableResponses can indicate whether they can be cached
Layered SystemThe client doesn’t know if there are proxies or load balancers between them
Code on Demand (optional)The server can send executable code to the client

HTTP Methods in REST

MethodOperationExample
GETRetrieve dataGET /users/123 → returns user 123
POSTCreate new resourcePOST /users → creates a new user
PUTFully updatePUT /users/123 → replaces user 123
PATCHPartially updatePATCH /users/123 → updates only the email
DELETERemoveDELETE /users/123 → deletes user 123

RESTful URL Design

A well-designed REST API uses nouns (not verbs) in URLs:

✅ RESTful:
GET    /products           → list of products
GET    /products/42        → product with ID 42
POST   /products           → create product
PUT    /products/42        → update product 42
DELETE /products/42        → delete product 42

❌ Not RESTful:
GET /getProducts
GET /getProduct?id=42
POST /createProduct
GET /deleteProduct?id=42

Responses and HTTP Status Codes

REST APIs use standard HTTP status codes:

CodeMeaningWhen used
200 OKSuccessSuccessful GET or PUT
201 CreatedResource createdSuccessful POST
204 No ContentSuccess with no bodySuccessful DELETE
400 Bad RequestInvalid requestMissing or incorrect data
401 UnauthorizedNot authenticatedNo token or invalid token
403 ForbiddenNo permissionsValid token but no access
404 Not FoundDoesn’t existResource not found
500 Server ErrorServer errorInternal bug

Real-World REST Response Example

// GET /orders/789
{
  "id": 789,
  "status": "preparing",
  "customer": {
    "id": 123,
    "name": "Ana García"
  },
  "items": [
    { "product": "Laptop", "quantity": 1, "price": 1299.99 }
  ],
  "total": 1299.99,
  "createdAt": "2026-03-10T14:30:00Z"
}

REST vs Other Alternatives

TechnologyIdeal use caseKey difference
RESTMost web APIsSimple, standard, broad support
GraphQLAPIs with complex, variable dataClient chooses exactly which fields to receive
gRPCInternal microservice communicationFaster, strict typing, less human-readable
SOAPLegacy or enterprise systemsMore verbose, stricter XML protocol

Why It Matters

When a development team says “we’ll build a REST API,” they’re making decisions that affect:

  • How easy it is to integrate the system with other tools
  • Performance and scalability
  • Documentation and maintainability
  • Developer experience for API consumers

A well-designed REST API lasts for years and can be consumed by web, mobile, and other systems without changes.

  • [[API]] - The general concept; REST is the most popular design style
  • [[Endpoint]] - Each URL in a REST API is an endpoint
  • [[JWT]] - The standard for authenticating REST API requests
  • [[Microservices]] - Architecture where each service exposes its own REST API

Additional Resources: