Skip to content

Software Development

API Design Best Practices: Versioning, Errors and Pagination

Practical rules for designing REST APIs that are easy to use and safe to change: naming, versioning, error responses, pagination and more.

VisionColab TeamSoftware engineering & AI 3 min read
API endpoints connecting applications with versioned request and response flows

In shortA well-designed API names resources with plural nouns, versions breaking changes only, returns one consistent error format (RFC 9457 is a good default), uses cursor pagination for large or changing data, accepts idempotency keys on payments and other retried writes, and is documented in an OpenAPI file before it ships.

An API is a contract. Once other teams, partners or customers build on it, every change you make can break their software. Good API design is mostly about making that contract clear from the start and changing it safely later.

This guide covers the decisions that matter most for HTTP/JSON APIs: resource naming, versioning, errors, pagination, and a few practices that prevent painful problems in production.

Name resources, not actions

Use nouns for URLs and let HTTP methods describe the action. Keep names plural and consistent.

ActionClearAvoid
List ordersGET /ordersGET /getAllOrders
Get one orderGET /orders/123GET /order?id=123
Create an orderPOST /ordersPOST /createOrder
Update part of an orderPATCH /orders/123POST /updateOrder
A customer’s ordersGET /customers/45/ordersGET /ordersByCustomer?c=45

Some operations really are actions, such as canceling an order. A sub-resource like POST /orders/123/cancellation keeps the style consistent.

Versioning: plan for change on day one

There are three common approaches:

  • In the URL: /v1/orders. Easy to see, test and route. The most common choice for public APIs.
  • In a header: keeps URLs clean but is less visible when debugging.
  • Date-based versions: clients pin to a release date. Useful for APIs that change often.

Whichever you choose, follow one rule: additive changes do not need a new version; breaking changes do. Adding an optional field is safe. Removing a field, renaming it, changing its type or changing what an endpoint means is breaking. When you do release a new version, publish a deprecation date for the old one and tell clients well in advance.

Errors: be consistent and useful

Use HTTP status codes correctly and return the same error shape everywhere. RFC 9457 (Problem Details for HTTP APIs) defines a standard JSON format that many teams adopt.

HTTP/1.1 422 Unprocessable Content
Content-Type: application/problem+json

{
  "type": "https://api.example.com/problems/invalid-quantity",
  "title": "Invalid quantity",
  "status": 422,
  "detail": "Quantity must be between 1 and 100.",
  "instance": "/orders/123"
}
  • 400 for malformed requests, 401 when authentication is missing, 403 when the user lacks permission, 404 when the resource does not exist, 409 for conflicts, 422 for validation failures, 429 for rate limits.
  • Use 5xx codes only for server faults, never for client mistakes.
  • Never return stack traces or internal details to clients. Log them on the server with a request ID, and include that ID in the response.

Pagination: choose cursors for large or changing data

MethodHow it worksGood forWeakness
Offset?limit=50&offset=100Small datasets, admin tables with page numbersSlow on large tables; items shift when data changes
Cursor?limit=50&after=eyJpZCI6MTIzfQFeeds, large or frequently updated datasetsNo jumping to an arbitrary page

Always set a default and a maximum page size, and return the information the client needs to fetch the next page, such as a next_cursor value or a link.

Other practices that prevent problems

  • Idempotency keys for create and payment requests, so a retried request does not create duplicates.
  • Consistent formats: ISO 8601 timestamps in UTC, one naming style for fields, and explicit currency codes with amounts.
  • Filtering and sorting with predictable parameters, such as ?status=paid&sort=-created_at.
  • Rate limits with clear 429 responses and headers that tell clients when to retry.
  • Machine-readable documentation using the OpenAPI Specification, kept in the same repository as the code.
  • Security by default: HTTPS only, authentication on every endpoint that needs it, and authorization checks on every object, not just every route.

A short pre-release checklist

  • Every endpoint is documented with examples.
  • Errors use one shape and correct status codes.
  • List endpoints are paginated with a maximum page size.
  • Retries are safe for create and payment operations.
  • A versioning and deprecation policy is written down.

Frequently asked questions

Should we use REST or GraphQL?

REST is simpler to cache, secure and document, and suits most business APIs. GraphQL helps when many different clients need flexible queries over related data.

How long should we support an old API version?

Long enough for your clients to migrate comfortably. Publish the date in advance and monitor who still uses the old version before switching it off.

Need an API built or reviewed?

VisionColab designs and builds APIs and integrations for web, mobile and AI products. See our web development services or book a free consultation.

Written by the VisionColab team

VisionColab designs and builds AI, web, mobile and cloud software for businesses. Our guides explain the decisions, costs and trade-offs involved in planning a software project.

Have a project in mind?

Share your goals and constraints. We will suggest a realistic scope and the right technology approach.