Back to all reviewers

REST principles first

expressjs/express
Based on 5 comments
JavaScript

When designing APIs with Express, prioritize proper REST principles and HTTP semantics over convenience. This ensures your API is predictable, standards-compliant, and maintainable:

API JavaScript

Reviewer Prompt

When designing APIs with Express, prioritize proper REST principles and HTTP semantics over convenience. This ensures your API is predictable, standards-compliant, and maintainable:

  1. Use appropriate HTTP verbs for different operations:
    • GET for retrieval
    • POST for creation
    • PUT for complete entity updates
    • PATCH for partial updates
    • DELETE for removal
// Implement both PUT and PATCH for different update scenarios
router.put('/:id', controller.replaceEntity.bind(controller));    // Full entity replacement
router.patch('/:id', controller.updateFields.bind(controller));   // Partial update
  1. Handle HTTP headers correctly:
    • Respect existing Content-Type headers before applying defaults
    • Follow established patterns for setting headers (use res.type() where appropriate)
    • Handle Link headers according to RFC specifications
    • Process Accept headers intelligently, considering priorities
  2. Follow consistent response patterns:
    • Use res.status() with appropriate status codes (200 OK, 201 Created, 204 No Content)
    • For error responses, use semantic status codes (400 Bad Request, 404 Not Found)
    • Use res.sendStatus() for simple status-only responses

Remember that proper HTTP semantics help clients understand your API intuitively without requiring extensive documentation for basic operations.

5
Comments Analyzed
JavaScript
Primary Language
API
Category

Source Discussions