Docs
/
Node Express
Chapter 11
11 — REST API Design
Core Concepts
- REST — Representational State Transfer (resource-oriented architecture)
- Resources — nouns, not verbs (
/usersnot/getUsers) - HTTP Methods — GET (read), POST (create), PUT (replace), PATCH (partial update), DELETE (remove)
- Status codes — communicate result type (2xx success, 4xx client error, 5xx server error)
- HATEOAS — include links for discoverability
- Idempotency — GET, PUT, DELETE should be safe to retry
REST Naming Conventions
| Action | Method | Endpoint | Status |
|---|---|---|---|
| List | GET | /api/users | 200 |
| Create | POST | /api/users | 201 |
| Read | GET | /api/users/:id | 200 |
| Replace | PUT | /api/users/:id | 200 |
| Partial Update | PATCH | /api/users/:id | 200 |
| Delete | DELETE | /api/users/:id | 200/204 |
| Nested | GET | /api/users/:id/posts | 200 |