REST APIs
Overview
REST APIs expose resources through HTTP in a predictable, client-friendly way.
Why It Matters
Many frontend applications depend on REST APIs for data loading, mutations, and workflow actions.
Core Concepts
- Resources represent domain concepts.
- HTTP methods map to operations.
- Status codes and payloads should be consistent.
Mental Models
Think in nouns for resources and verbs for operations.
Best Practices
- Keep route naming consistent.
- Return stable shapes.
- Use clear error responses.
Common Mistakes
- Building RPC-style endpoints with REST labels.
- Returning inconsistent error shapes.
- Encoding too much business logic in route names.
Trade-offs
REST is simple and familiar, but very complex workflows sometimes need a more specialized design.
Decision Framework
| Choice | Prefer |
|---|---|
| Fetch a resource | GET /resource/:id |
| Create a resource | POST /resource |
| Update a resource | PATCH or PUT depending on semantics |
Examples
GET /users/123POST /sessionsPATCH /profile
Checklists
- Are routes consistent and predictable?
- Do errors return useful information?
- Are methods aligned with the operation?
Senior Engineer Notes
Senior engineers value API clarity because it reduces frontend guesswork and production confusion.