REST API Design with Express: Conventions That Scale

REST API Design with Express: Conventions That Scale

Naming, status codes, validation, pagination and errors: conventions that keep an Express API easy to use and maintain.

A good API is boring in the best way: every endpoint behaves the way you expect. These conventions keep Express APIs that way as they grow.

Resources, not actions

Use plural nouns and HTTP verbs: GET /orders, POST /orders, PATCH /orders/:id. Reserve verb-style routes for true actions, such as POST /orders/:id/cancel.

Meaningful status codes

  • 200 for reads and updates, 201 for creates, 204 for deletes with no body.
  • 400 for invalid input, 401 when not signed in, 403 when not allowed, 404 when missing.
  • 409 for conflicts such as duplicates, 422 for valid JSON that breaks business rules.

Validate at the edge

Validate every request body and query with a schema before it reaches business logic. Invalid data never touches the database, and errors are consistent.

One error shape

{
  "error": {
    "code": "ORDER_NOT_FOUND",
    "message": "Order 123 does not exist",
    "details": []
  }
}

Use cursor pagination for feeds and large collections: return a nextCursor and accept it on the next call. Offset pagination is fine for small admin tables.

Version when you break things

Prefix routes with /v1. Add fields freely, but when a change breaks clients, release it under /v2 and keep /v1 running until clients migrate.

More on this topic

Photography
3D Models
Development
Illustrations
Fashion
Digital Art
Packaging
Motion
Illustrations
Video Production
Photography
3D Models
Development
Illustrations
Fashion