Skip to content

Cloud & DevOps

REST API best practices

Practical rules for designing REST APIs that developers enjoy using: clear resources, correct status codes, safe retries, sensible pagination, versioning and security.

EveTek Engineering · · 7 min read

Close-up of API code and JSON responses on a dark editor screen

An API is a product. Its users are developers: your own frontend team, mobile apps, partners and sometimes the public. A well-designed API is predictable, so people can guess how an endpoint behaves before reading the docs. A poorly designed one generates support tickets, integration bugs and workarounds that outlive the original team.

This guide collects practical rules for designing REST APIs over HTTP. They are not the only valid choices, but they are widely understood, and consistency matters more than any single rule.

Model resources, not actions

REST organises an API around resources, the nouns of your domain, and uses HTTP methods as the verbs.

Method Purpose Example
GET Read a resource or collection GET /orders/123
POST Create a resource, or trigger a process POST /orders
PUT Replace a resource entirely PUT /orders/123
PATCH Update part of a resource PATCH /orders/123
DELETE Remove a resource DELETE /orders/123

Some conventions that keep URLs readable:

  • Use plural nouns for collections: /customers, /invoices.
  • Nest only where the relationship is real and shallow: /customers/42/addresses is fine; four levels deep is not.
  • Use lowercase and hyphens: /payment-methods, not /paymentMethods.
  • Keep verbs out of paths, except for genuine processes that do not map to a resource. POST /orders/123/cancel is a reasonable, widely used exception when cancellation has side effects beyond changing a field.

Respect method semantics. GET must never change data. PUT and DELETE should be idempotent, meaning repeating the same request has the same effect as sending it once. Proxies, caches, browsers and retry logic all rely on these guarantees.

Use status codes correctly

Status codes let clients react without parsing message text. You do not need dozens. A dependable core set covers most needs:

Code Meaning Use when
200 OK Success with a body Reads and updates that return data
201 Created New resource created Successful POST; include a Location header
204 No Content Success, no body Deletes or updates with nothing to return
400 Bad Request Malformed request Invalid JSON, wrong types
401 Unauthorized Not authenticated Missing or invalid credentials
403 Forbidden Authenticated but not allowed Valid user, insufficient permission
404 Not Found Resource does not exist Or the caller may not know it exists
409 Conflict State conflict Duplicate, or version mismatch
422 Unprocessable Content Valid syntax, failed validation Business rule failures
429 Too Many Requests Rate limited Include Retry-After
500 Internal Server Error Unexpected server failure Never for client mistakes
503 Service Unavailable Temporarily down Maintenance or overload

Never return 200 OK with an error hidden in the body. It breaks monitoring, caching and every client that checks the status first.

Return consistent, useful errors

Pick one error format and use it everywhere. The IETF standard Problem Details for HTTP APIs (RFC 9457) is a good default, served with the application/problem+json media type:

{
  "type": "https://api.example.com/problems/validation-error",
  "title": "Your request did not pass validation",
  "status": 422,
  "detail": "Two fields are invalid.",
  "instance": "/orders",
  "errors": [
    { "field": "deliveryDate", "message": "Must be in the future" },
    { "field": "quantity", "message": "Must be at least 1" }
  ]
}

Good error responses tell the developer what went wrong and how to fix it. Include a request or trace ID so support can find the matching server logs. Never leak stack traces, SQL, internal hostnames or secrets.

Design request and response bodies with care

  • Be consistent with naming. Choose camelCase or snake_case and stick with it across every endpoint.
  • Use standard formats. ISO 8601 for dates and times with a time zone (2026-11-05T09:30:00Z), ISO 4217 codes for currencies, and strings or integer minor units for money rather than floating-point numbers.
  • Use stable, opaque IDs. UUIDs or similar identifiers avoid leaking record counts and make IDs hard to guess.
  • Avoid exposing your database schema. The API is a contract; your tables are an implementation detail that will change.
  • Return the resource after create and update. It saves a round trip and shows the client any server-set fields.
  • For PATCH, be explicit about the format. JSON Merge Patch (RFC 7396) is simple and covers most cases.

Make writes safe to retry

Networks fail. A mobile client on a train may send a payment request, lose the connection and not know whether it succeeded. If it retries, you must not charge twice.

The common solution is an idempotency key. The client generates a unique value and sends it in a header with the POST:

POST /payments
Idempotency-Key: 8f14e45f-ceea-4e7a-9b1c-2f6d1a0b7c33
Content-Type: application/json

The server stores the key with the result. If the same key arrives again, it returns the original response instead of processing the request twice. Payment providers popularised this pattern, and it is being standardised at the IETF. Use it for any operation where duplicates cause harm: payments, orders, bookings and messages.

For updates, prevent lost writes with optimistic concurrency. Return an ETag with each resource, require clients to send it back in If-Match when updating, and respond with 412 Precondition Failed if someone else changed the record in the meantime.

Paginate, filter and sort predictably

Never return an unbounded collection. Even small tables grow.

Style How it works Strengths Weaknesses
Offset ?limit=50&offset=100 Simple, supports jumping to a page Slow on large tables; items shift when data changes
Cursor ?limit=50&after=eyJpZCI6MTIzfQ Fast and stable on large or live data No jumping to arbitrary pages

Cursor pagination is usually the better default for APIs, especially for feeds and large datasets. Return the next cursor in the response body or a Link header, and set a sensible default and maximum page size.

For filtering and sorting, use simple, documented query parameters: ?status=paid&createdAfter=2026-01-01&sort=-createdAt. Allow only fields you have indexed, or performance will suffer as data grows.

Version deliberately

Your API will change. Plan for it from the first release.

  • Additive changes are safe. New optional fields, new endpoints and new optional parameters should not break clients, as long as clients ignore fields they do not recognise. Tell them to.
  • Breaking changes need a new version. Removing or renaming fields, changing types or changing behaviour all break someone.
  • Pick one versioning scheme. A path prefix like /v1/ is the most visible and easiest to route. Header-based or date-based versioning also work well when applied consistently.
  • Deprecate politely. Announce timelines, signal deprecation in responses (the Deprecation and Sunset headers exist for this), and monitor who still calls old versions before switching them off.

Secure every endpoint

APIs are a common attack surface. The OWASP API Security Top 10 is a useful reference; broken object-level authorisation consistently ranks at the top.

  • Use HTTPS everywhere. No exceptions, including internal services.
  • Authenticate with proven standards. OAuth 2.0 and OpenID Connect for user-facing access, with short-lived tokens. API keys only for simple server-to-server cases, and treat them as secrets.
  • Authorise every object. Checking that a user is logged in is not enough. Confirm they may access this order, this invoice, this record.
  • Validate all input against a schema, and reject unexpected fields on writes.
  • Rate limit per client and per endpoint, and return 429 with Retry-After.
  • Limit what you return. Do not send fields the client does not need, especially personal data.
  • Log and monitor authentication failures, permission denials and unusual traffic patterns.

Document, test and observe

  • Write an OpenAPI description. OpenAPI 3.1 aligns with JSON Schema and lets you generate documentation, client SDKs, mock servers and contract tests from one source.
  • Design first when you can. Agreeing the contract before building lets frontend and backend teams work in parallel.
  • Test the contract. Automated tests should confirm responses match the documented schema and that errors follow your format.
  • Add observability. Log each request with a trace ID, track latency and error rates per endpoint, and use distributed tracing (OpenTelemetry is the common standard) across services.
  • Cache what you can. Use Cache-Control and ETag headers for responses that do not change often.

A quick review checklist

  1. Resource-based URLs with plural nouns and correct HTTP methods
  2. Accurate status codes and no errors hidden in 200 responses
  3. One consistent error format, ideally RFC 9457
  4. Idempotency keys on sensitive POSTs; ETags for concurrent updates
  5. Pagination on every collection, with sensible limits
  6. A clear versioning and deprecation policy
  7. Authentication, per-object authorisation, validation and rate limiting
  8. An up-to-date OpenAPI description and contract tests
  9. Request tracing, metrics and alerts

How EveTek can help

We design, build and review APIs as part of our custom software development and cloud and DevOps work, using stacks such as Node.js, .NET and Python. Our software testing and QA team can add contract and security testing to an existing API. Talk to us about yours.

Keep reading

Ready to build yours?

Tell us what you're planning. You'll get a written plan with scope, timeline and price, usually within a few working days.