- 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:
| Method | Meaning | Example |
|---|---|---|
| GET | Read | GET /users/42 |
| POST | Create | POST /users |
| PUT | Replace | PUT /users/42 |
| PATCH | Partial update | PATCH /users/42 |
| DELETE | Remove | DELETE /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:
| Code | Meaning |
|---|---|
| 200 | OK |
| 201 | Created |
| 204 | No Content |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 409 | Conflict |
| 500 | Server 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)
| Style | Key idea |
|---|---|
| REST | Resources + HTTP semantics |
| RPC | Call functions (getUser()) |
| GraphQL | Client chooses data shape |
| gRPC | Binary, 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