Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.

Best practices · Stacks and tools

REST API Design Best Practices

Opens with credits

A language-agnostic guide to REST API design for developers who build HTTP APIs that other teams, apps or customers depend on. It covers resource and URL design, HTTP method semantics, status codes, RFC 9457 error responses, payload conventions, pagination and filtering, idempotency and concurrency control, and versioning, deprecation and documentation with OpenAPI.

Written by Tauseef Fayyaz8 chapters, 31 practicesAbout 20 min31 quiz questionsReviewed 13 October 2026

What you will learn

8 chapters · about 20 min

  1. 1Resources and URLsHow to model an API as resources and name their URLs so they stay predictable as the API grows.4 practices · 3 min
  2. 2HTTP methods and their promisesWhat GET, POST, PUT, PATCH, DELETE and the new QUERY method promise to clients and intermediaries, and how to keep those promises.4 practices · 3 min
  3. Status codesChoosing status codes that let clients react correctly without parsing the body, and the headers some codes require.4 practices · 3 minOpens with credits
  4. Error responsesReturning errors in one standard, machine-readable format that clients can handle without special cases.4 practices · 2 minOpens with credits
  5. Request and response bodiesConventions for JSON payloads that keep an API consistent, unambiguous and easy to extend.4 practices · 2 minOpens with credits
  6. Pagination, filtering and sortingHow to return large collections in pages that stay fast and correct, and how to let clients filter and sort safely.4 practices · 2 minOpens with credits
  7. Idempotency, concurrency and cachingMaking retries safe, stopping clients from overwriting each other and letting caches do their job.3 practices · 2 minOpens with credits
  8. Versioning, deprecation and documentationHow to change an API without breaking the people who depend on it, and how to describe it so they can use it without asking you.4 practices · 3 minOpens with credits

About this guide

REST API design best practices are about the decisions that are expensive to change once someone depends on them. Code behind an API can be rewritten in a weekend. The URLs, status codes, field names and error shapes clients have built against are a contract, and every inconsistency in them becomes a special case in somebody else's code for years.

This guide is language-agnostic: it is about the HTTP interface, not the framework behind it. It starts with resources and URLs, then covers what each HTTP method promises, choosing status codes, returning errors in the standard problem details format, conventions for request and response bodies, pagination, filtering and sorting, making retries safe with idempotency keys and ETags, and finally evolving an API with versioning, deprecation headers and an OpenAPI description.

The advice was checked against the HTTP standards themselves: RFC 9110 for HTTP semantics, RFC 9457 for problem details, RFC 10008 for the new QUERY method (published June 2026), RFC 9745 for the Deprecation header, the IETF Idempotency-Key draft, and the OpenAPI Specification 3.2.1. Server-side implementation concerns such as input validation, logging and rate limiting middleware belong to your framework's own guide.

Common questions

Should I use PUT or PATCH to update a resource?

Use PUT to replace the whole resource: fields you leave out are removed or reset. Use PATCH to change only some fields, ideally with JSON Merge Patch (application/merge-patch+json). Most update forms in apps map to PATCH.

Should validation errors return 400 or 422?

400 fits malformed requests such as invalid JSON. 422 Unprocessable Content fits requests that are well-formed but fail validation rules. Many APIs use 400 for both. Pick one rule, document it and apply it everywhere.

What is the best way to version a REST API?

A version in the path (/v1/), a version header or a media type all work. The important parts are using one scheme for the whole API, versioning only for breaking changes, and announcing retirement with the Deprecation and Sunset headers.

Cursor or offset pagination?

Cursor pagination stays fast on deep pages and does not repeat or skip items when data changes, so use it for feeds, logs and large collections. Offset pagination is simpler and allows jumping to a page number, which suits small admin tables.

What is the standard format for API error responses?

RFC 9457 Problem Details, with the application/problem+json media type and the members type, title, status, detail and instance. It replaced RFC 7807 in July 2023, and most web frameworks support it.

What is the HTTP QUERY method?

A method defined in RFC 10008 (June 2026) that sends a query in the request body while being safe and idempotent, like GET. It suits searches too large or sensitive for a URL. Check that your framework, proxies and clients support it before relying on it.

Sources (8)

Checked against these, last on 13 October 2026.

  1. RFC 9110: HTTP Semantics, IETFwww.rfc-editor.org/rfc/rfc9110.html
  2. RFC 9457: Problem Details for HTTP APIs, IETFwww.rfc-editor.org/rfc/rfc9457.html
  3. RFC 10008: The HTTP QUERY Method, IETFwww.rfc-editor.org/rfc/rfc10008.html
  4. RFC 9745: The Deprecation HTTP Response Header Field, IETFwww.rfc-editor.org/rfc/rfc9745.html
  5. RFC 6585: Additional HTTP Status Codes, IETFwww.rfc-editor.org/rfc/rfc6585.html
  6. RFC 8288: Web Linking, IETFwww.rfc-editor.org/rfc/rfc8288.html
  7. The Idempotency-Key HTTP Header Field, IETF HTTPAPI Working Groupdatatracker.ietf.org/doc/draft-ietf-httpapi-idempotency-key-header/
  8. OpenAPI Specification v3.2.1, OpenAPI Initiativespec.openapis.org/oas/latest.html

Picked from the other libraries by shared topics.

Work with me

Stuck on something specific?

Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.

  • 1:1 Mentorship
  • Fresh Graduate Mentorship
  • Career Guidance

Brand deals, promos and partnerships: tauseeffayyaz@gmail.com