Published on

What is RESTful API?

A RESTful API is a way for software systems to talk to each other over HTTP using a simple, predictable set of rules. REST stands for Representational State Transfer—a design style, not a protocol.

Think of it as:

“Use the web the way the web was meant to be used.”


Core idea (in one sentence)

A RESTful API exposes resources (things) via URLs, manipulates them using standard HTTP methods, and exchanges representations (usually JSON).


1️⃣ Resources (nouns, not verbs)

Everything is a resource, identified by a URL:

/users
/users/42
/orders/123/items

✔ Good

GET /users/42

❌ Not RESTful

GET /getUser?id=42

Resources are nouns, actions come from HTTP verbs.


2️⃣ HTTP methods (the actions)

REST reuses standard HTTP verbs with clear meanings:

MethodMeaningExample
GETReadGET /users/42
POSTCreatePOST /users
PUTReplacePUT /users/42
PATCHPartial updatePATCH /users/42
DELETERemoveDELETE /users/42

This is one of REST’s biggest wins: no custom action vocabulary.


3️⃣ Statelessness

Each request is independent.

  • The server does not remember previous requests
  • All required info is in the request (headers, tokens, body)

✔ Example:

Authorization: Bearer <token>

This makes APIs:

  • Easier to scale
  • Easier to cache
  • Easier to debug

4️⃣ Representations (usually JSON)

The API returns a representation of a resource:

{
  "id": 42,
  "name": "Alice",
  "email": "alice@example.com"
}

Same resource, different formats are possible:

  • JSON (most common)
  • XML
  • HTML (rare in APIs)

5️⃣ Proper HTTP status codes

RESTful APIs use HTTP status codes correctly:

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

❌ Bad:

{ "success": false, "errorCode": 404 }

✔ Good:

HTTP/1.1 404 Not Found

6️⃣ Optional but “more REST”: HATEOAS

Hypermedia links guide the client:

{
  "id": 42,
  "name": "Alice",
  "links": {
    "self": "/users/42",
    "orders": "/users/42/orders"
  }
}

Very “pure REST”, rarely used in practice—but good to know.


What REST is not

  • ❌ Not tied to JSON (that’s just common)
  • ❌ Not the same as HTTP (it uses HTTP)
  • ❌ Not enforced by a spec like OpenAPI
  • ❌ Not automatically “good design”

REST vs others (quick comparison)

StyleKey idea
RESTResources + HTTP semantics
RPCCall functions (getUser())
GraphQLClient chooses data shape
gRPCBinary, high-performance RPC

Minimal RESTful example

POST /users
Content-Type: application/json

{
  "name": "Alice"
}

Response:

HTTP/1.1 201 Created
Location: /users/42

One-line summary

A RESTful API is an API that:

  • models data as resources
  • uses HTTP methods correctly
  • is stateless
  • returns representations with proper status codes