DEV Community

Cover image for A Complete Guide to REST and RESTful API Design
Ajay Kumbham
Ajay Kumbham

Posted on • Originally published at blog-ajaykumbham.vercel.app

A Complete Guide to REST and RESTful API Design

A Complete Guide to REST & RESTful API Design (For Beginners to Advanced)

Everything you need to understand REST, its core constraints, and how to design clean, scalable APIs.


Introduction

Today, almost every modern application — from mobile apps to enterprise systems — uses APIs to communicate. Among the most widely used architectural styles for building APIs is REST (Representational State Transfer).

However, REST is often misunderstood. Many developers think that “using JSON over HTTP” automatically makes their API RESTful — but REST is much deeper than that.

In this blog, you’ll learn:

  • What REST actually is
  • The 5 mandatory REST constraints
  • What makes an API truly RESTful
  • Best practices and naming rules
  • Common mistakes developers make
  • Clear examples to help you remember each principle

Let’s begin.


What Is REST?

REST (Representational State Transfer) is an architectural style for designing networked applications. It was introduced by Roy Fielding in his PhD dissertation and is based on a set of rules (constraints) that ensure:

  • Scalability
  • Simplicity
  • Performance
  • Loose coupling between client and server

REST is not a protocol, not a library, and not tied to JSON or HTTP.
But in practice, RESTful APIs use HTTP as the transport protocol.


REST vs RESTful

  • REST → Architecture, theory
  • RESTful API → Implementation that follows REST constraints

If an API does not follow the required constraints, it is simply HTTP API, not REST.


The 5 Mandatory REST Constraints

These are the non-negotiable principles that define REST.
Every RESTful API must follow them.


1. Client–Server Architecture

REST strictly separates:

  • Client → Responsible for UI
  • Server → Responsible for data and business logic

They can evolve independently.

Benefits:

  • Easier scaling
  • Flexibility in technology choices
  • Separation of concerns

2. Statelessness

A REST API must be stateless, meaning:

  • The server does not remember anything from previous requests.
  • Each request must include all necessary information (auth token, parameters, etc.)

Example:
A banking API must receive account number/token every time, even if it was sent earlier.

Benefits:

  • Easy horizontal scaling
  • No server-side sessions
  • Simpler debugging and reliability

3. Cacheability

REST requires that responses explicitly declare whether they are cacheable.

For example:

Cache-Control: max-age=3600
Enter fullscreen mode Exit fullscreen mode

This means:

“The client may reuse this response for 1 hour.”

Important:
Caching is not forced.
REST only requires the server to mark data as cacheable or non-cacheable.

Why this matters:

  • Prevents clients from caching sensitive or changing data accidentally
  • Improves performance for safe, static data

4. Uniform Interface (The Heart of REST)

This is the most important constraint.
It ensures that all parts of the system interact in a standard, predictable way.

Uniform Interface has four rules:

4.1 Resource Identification in URLs

URLs identify resources (nouns), not actions.

/users/12
/getUserDetails


4.2 Manipulation Through Representations

Clients modify resources by sending JSON/XML that represents the updated state.

Example:

PUT /users/12
{
  "name": "Ajay"
}
Enter fullscreen mode Exit fullscreen mode

4.3 Self-Descriptive Messages

Each request must contain enough information to be understood:

  • HTTP method (GET/POST)
  • Headers
  • Body format
  • Status codes

No hidden meaning or special rules.


4.4 HATEOAS (Hypermedia as the Engine of Application State)

The server may provide links that guide the client.

Example:

{
  "id": 10,
  "links": {
    "self": "/users/10",
    "orders": "/users/10/orders"
  }
}
Enter fullscreen mode Exit fullscreen mode

Although optional in practice, HATEOAS is part of true REST uniform interface.


5. Layered System

The client must not care how many internal layers the system has.

A request may pass through:

  • API gateway
  • Proxy
  • Load balancer
  • Auth server
  • Microservice

The client sees all as a single endpoint.

Benefit:
Flexible, scalable architecture.


Optional REST Constraint (Bonus)

Code on Demand

Servers may send executable code to clients (e.g., JavaScript).
This is optional and almost never used in APIs.


RESTful API Design Principles (Must-Follow Best Practices)

Now that we know REST constraints, let’s look at RESTful design rules commonly expected in industry.


Use Proper HTTP Methods

Method Meaning
GET Fetch resource
POST Create resource
PUT Full update
PATCH Partial update
DELETE Remove resource

Use Nouns, Not Verbs, in URLs

/products/10
/fetchProductDetails


Use Plural Resource Names

/users
/users/21/orders


Use Query Parameters for Filtering and Pagination

Example:

GET /products?category=mobile&sort=price&limit=20&page=2
Enter fullscreen mode Exit fullscreen mode

Use Meaningful HTTP Status Codes

  • 200 OK
  • 201 Created
  • 204 No Content
  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
  • 409 Conflict
  • 500 Server Error

Common Misconceptions About REST

“If I use JSON, my API is RESTful.”

REST has nothing to do with JSON.

“Using HTTP automatically makes it REST.”

REST requires strict constraints.

“HATEOAS is optional.”

For real REST (as defined by Fielding), it’s mandatory, but most APIs skip it.

“GET requests can have a body.”

They shouldn’t — many proxies will block them.


REST vs Other Approaches

Feature REST GraphQL gRPC
Style Architecture Query Language RPC Framework
Format JSON/XML JSON Protobuf
Best for Public APIs Complex queries High-performance microservices
Type safety Low Medium High

Conclusion

REST is not just “API with JSON.”
It is a well-defined architectural style with strict constraints.

A truly RESTful API must follow:

  1. Client–Server
  2. Statelessness
  3. Cacheability
  4. Uniform Interface
  5. Layered System

And use recommended practices like proper HTTP methods, clear status codes, nouns in URLs, and consistent structure.

By understanding the purpose of each rule — not just memorizing them — you’ll be able to design clean, scalable, maintainable APIs that work well in real-world systems.

Top comments (0)