REST Architectural Constraints
debt(d7/e7/b7/t7)
Closest to 'only careful code review or runtime testing' (d7), since semgrep can flag some patterns (verbs in URLs, wrong status codes) but most REST violations like statelessness or missing HATEOAS require human API review.
Closest to 'cross-cutting refactor across the codebase' (e7), because fixing REST violations (removing session state, restructuring URLs, adding HATEOAS links, correcting status codes) touches every endpoint in the API.
Closest to 'strong gravitational pull' (b7), since the choice of REST constraints (or violation thereof) shapes every endpoint, auth strategy, and client integration across the API surface.
Closest to 'serious trap' (t7), per the misconception that any JSON-over-HTTP API is REST; developers confidently build 'REST APIs' that violate statelessness and HATEOAS without realizing it.
Also Known As
TL;DR
Explanation
Roy Fielding's REST dissertation defines six constraints: Stateless (server holds no session state — each request is self-contained), Uniform Interface (consistent resource identification via URIs, manipulation via representations, self-descriptive messages, HATEOAS), Client-Server separation, Cacheable responses, Layered System (client cannot tell if it's talking to a proxy or origin), Code on Demand (optional — return executable code). Most 'REST' APIs violate HATEOAS, making them HTTP APIs rather than truly RESTful. Understanding the constraints explains why stateless APIs scale better.
Common Misconception
Why It Matters
Common Mistakes
- Session-based authentication in a 'REST' API — violates statelessness; use JWT or API keys.
- Verbs in URLs: POST /createUser — REST uses nouns (POST /users); the HTTP method is the verb.
- Ignoring HATEOAS — without links, clients must hardcode URLs; with HATEOAS, the API is self-discoverable.
- Status 200 for errors — violates uniform interface; clients cannot distinguish success from failure without parsing the body.
Code Examples
// Not REST — verbs in URLs, wrong HTTP methods, stateful:
POST /api/getUser?id=42 // Verb in URL, wrong method
POST /api/deleteOrder?id=10 // Should be DELETE /api/orders/10
GET /api/createProduct // GET should be read-only
// Session stored on server — violates stateless constraint
// REST-aligned:
GET /api/users/42 // Get user
POST /api/users // Create user
PUT /api/users/42 // Replace user
PATCH /api/users/42 // Partial update
DELETE /api/orders/10 // Delete order
// HATEOAS response:
{
"id": 42,
"name": "Alice",
"_links": {
"self": {"href": "/api/users/42"},
"orders": {"href": "/api/users/42/orders"}
}
}