Backend6 min read

REST API Designer

Designs RESTful APIs that developers enjoy using - resource naming, HTTP semantics, OpenAPI specs, versioning strategy, and consistent error responses.

RESTAPI designOpenAPIversioningerror responsesHTTP

The REST API Designer creates APIs that follow HTTP semantics correctly and are pleasant for developers to integrate against. Good API design is mostly about consistency - consistent resource naming, consistent error shapes, and consistent behaviour that lets developers build mental models quickly.

Resource Naming Rules

PatternCorrectIncorrect
Plural nouns for collectionsGET /usersGET /getUsers
Nested for ownershipGET /users/123/postsGET /posts?userId=123
Kebab-case only/payment-methods/paymentMethods
Actions as sub-resourcesPOST /invoices/42/sendPOST /sendInvoice/42
No trailing slash/users/123/users/123/

HTTP Method Semantics

GET    /users          → 200 + list of users (never mutates)
POST   /users          → 201 + created user (body required)
GET    /users/123      → 200 + user, or 404
PUT    /users/123      → 200 + updated user (full replacement)
PATCH  /users/123      → 200 + updated user (partial update)
DELETE /users/123      → 204 No Content (no body on success)

# Idempotency: GET, PUT, DELETE, PATCH are idempotent
# POST is NOT idempotent - avoid retrying without deduplication key

Error Response Format

// Consistent error shape across all endpoints
{
  "error": {
    "code": "VALIDATION_ERROR",        // Machine-readable code
    "message": "Request validation failed", // Human-readable summary
    "details": [                        // Optional: field-level errors
      { "field": "email", "message": "Must be a valid email address" },
      { "field": "name",  "message": "Required" }
    ],
    "requestId": "req_01hzx..."         // Correlates to server logs
  }
}

// Status codes:
// 400 Bad Request    - client sent invalid data
// 401 Unauthorized   - not authenticated
// 403 Forbidden      - authenticated but not authorised
// 404 Not Found      - resource doesn't exist
// 409 Conflict       - state conflict (duplicate, version mismatch)
// 422 Unprocessable  - valid syntax, invalid semantics
// 429 Too Many Req.  - rate limited
// 500 Internal Error - server bug (never expose stack traces)

Versioning Strategy

  • URL versioning (/v1/users) - most visible, easy to route, works with any HTTP client. Recommended for public APIs.
  • Header versioning (API-Version: 2026-01-01) - cleaner URLs; requires custom routing. Used by Stripe.
  • When to version: breaking changes only. Adding fields, adding endpoints, and making required fields optional are backwards-compatible - no new version needed.
  • Breaking changes: removing fields, renaming fields, changing field types, changing error codes, changing auth flow.

Explore all agents

Browse the full library of specialized AI agents.