Back to API development

API development

API design principles

Predictable resources, methods and responses that developers understand without reading the manual

Anatomy of a well-designed request

1 / 8

HTTP method

GET reads without side effects, so the response can be cached and the call safely retried.

HTTP/1.1 200 OK{  "data": [    { "id": 7731, "total": 1250.0, "status": "open" },    { "id": 7702, "total": 980.5, "status": "open" }  ],  "hasMore": true,  "nextCursor": "def456"}

Illustrative example

Every part of a request has a job. When each one follows the conventions, consumers can guess the next endpoint correctly.

RESTful resource design

URI design best practices

  • Use nouns, not verbs: /customers not /getCustomers
  • Hierarchical relationships: /customers/123/orders
  • Plural resource names: /products not /product
  • Use hyphens for readability: /customer-orders not /customer_orders
  • Lowercase URIs: /customers not /Customers

HTTP methods & semantics

MethodPurposeIdempotentExample
GETRetrieve resource(s)YesGET /customers/123
POSTCreate new resourceNoPOST /customers
PUTReplace entire resourceYesPUT /customers/123
PATCHPartial updateNoPATCH /customers/123
DELETERemove resourceYesDELETE /customers/123

Response design

HTTP status codes

  • 200 OK:Successful GET, PUT, PATCH, or DELETE
  • 201 Created:Successful POST with location header to new resource
  • 204 No Content:Successful request with no response body
  • 400 Bad Request:Invalid request syntax or validation errors
  • 401 Unauthorized:Authentication required
  • 403 Forbidden:Authenticated but not authorized
  • 404 Not Found:Resource does not exist
  • 409 Conflict:Resource state conflict (e.g., duplicate)
  • 429 Too Many Requests:Rate limit exceeded
  • 500 Internal Server Error:Unhandled server error

Error response format

Consistent error responses improve developer experience:

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid email format",
    "target": "email",
    "details": [
      {
        "field": "email",
        "message": "Must be a valid email address"
      }
    ]
  }
}

Pagination, filtering & sorting

Pagination strategies

  • Offset-based: ?skip=20&limit=10 - Simple but inefficient for large datasets
  • Cursor-based: ?cursor=abc123&limit=10 - Efficient for real-time data
  • Page-based: ?page=3&pageSize=10 - User-friendly for UI pagination

Include pagination metadata in response: totalCount, hasMore, nextCursor

Filtering & sorting

  • Simple filters: ?status=active&category=electronics
  • Comparison operators: ?price[gte]=100&price[lte]=500
  • Full-text search: ?q=laptop&searchFields=name,description
  • Sorting: ?sortBy=createdAt&order=desc
  • Field selection: ?fields=id,name,email

Ready to build reliable, well-documented APIs?

Let's discuss how well-designed APIs can power your digital ecosystem with secure, scalable, and developer-friendly services.