REST Principles
What REST means (constraints)
- REST is an architectural style, not a framework: constraints include client-server, statelessness, cacheability, layered system, and (classically) a uniform interface.
- HATEOAS (hypermedia as the engine of application state) is part of the original model but is often skipped in practice.
- Practical APIs claim “RESTful” when they follow resources + HTTP semantics even if they are not hypermedia-driven.
Statelessness
- Each request should carry everything the server needs to authorize and process it (tokens, correlation IDs, context headers).
- The server should not rely on in-memory session affinity for correctness (scaling and failover get painful if it does).
- You can still use external stores (Redis, DB) for sessions or idempotency keys; the constraint is about not hiding required context only on the server node.
Resource-based design
- Model the world as nouns (resources) identified by URLs, not as unlimited RPC-style
/doSomething endpoints.
- Use HTTP methods to express intent on a resource (GET read, DELETE remove, etc.).
- Prefer stable identifiers (
/users/{id}) over operation names in the path.
- Same patterns everywhere: predictable URLs, methods, status codes, and error shapes.
- Clients can rely on HTTP semantics instead of custom conventions per endpoint.
- Hypermedia links in responses are optional but improve discoverability when used.
Client-server separation
- Clients handle presentation and UX; servers handle data, rules, and persistence.
- This boundary lets you evolve backends and ship multiple clients against one API.
- Avoid leaking internal implementation details (table names, stack traces) across the boundary.