TutorialsAPIREST Principles
API

REST Principles

REST (Representational State Transfer) is the most common architectural style for web APIs. A RESTful API organizes everything around resources accessed via predictable URLs and standard HTTP methods.

Resource-based URLs

URLs name things (nouns), not actions. The HTTP method describes the action.

✅ Good (RESTful)            ❌ Avoid
GET    /users               GET /getAllUsers
GET    /users/42            GET /getUserById?id=42
POST   /users               POST /createUser
DELETE /users/42            POST /deleteUser?id=42

Nesting resources

Express relationships through the URL hierarchy:

GET /users/42/posts          → all posts by user 42
GET /users/42/posts/7        → post 7 by user 42
POST /users/42/posts         → create a post for user 42

Core REST principles

  • Statelessness — each request contains everything the server needs; the server keeps no session memory between requests. This makes APIs easy to scale.
  • Uniform interface — consistent, predictable URLs and methods.
  • Client–server separation — the frontend and backend evolve independently.
  • Cacheability — responses can declare whether they're cacheable.
💡

Statelessness is key: because the server doesn't remember previous requests, you can run many identical server instances behind a load balancer.

A consistent response shape

Good APIs return predictable structures so clients can rely on them:

{
  "data": [ { "id": 1, "name": "Priya" } ],
  "meta": { "page": 1, "total": 50 }
}

And consistent errors:

{
  "error": { "code": "NOT_FOUND", "message": "User not found" }
}

Watch & Learn

A recommended video to watch alongside this chapter.

More “REST Principles” videos on YouTube