04-backend-knowledge

REST APIs

04-backend-knowledge/rest-apis

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

ChoicePrefer
Fetch a resourceGET /resource/:id
Create a resourcePOST /resource
Update a resourcePATCH or PUT depending on semantics

Examples

  • GET /users/123
  • POST /sessions
  • PATCH /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.


Further Reading