Docs
/
Node Express
Chapter 11

11 — REST API Design

Core Concepts

  • REST — Representational State Transfer (resource-oriented architecture)
  • Resources — nouns, not verbs (/users not /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

ActionMethodEndpointStatus
ListGET/api/users200
CreatePOST/api/users201
ReadGET/api/users/:id200
ReplacePUT/api/users/:id200
Partial UpdatePATCH/api/users/:id200
DeleteDELETE/api/users/:id200/204
NestedGET/api/users/:id/posts200