What Are REST API Patterns?
REST API patterns are repeatable design decisions that make an HTTP API predictable. The most common ones are modelling resources instead of actions, using HTTP methods and status codes as defined, paginating collections, returning consistent errors, making retries safe with idempotency keys, versioning and deprecating deliberately, caching and rate-limiting, and publishing an OpenAPI description. This page walks through eight such patterns and links each to the standards, style guides and vendor documentation that define it.
Foundations & Style Guides
7 entriesPrimary sources and public style guides behind the patterns below. The Level Up Coding article that prompted this page is a Medium member-only story, so this page links to it and builds its own pattern list from standards and published guidelines.
Pattern 1: Model Resources, Not Actions
3 entriesName things, not operations. A URL identifies a resource, such as /orders or /orders/{id}, and the HTTP method says what to do with it, so avoid endpoints like /getOrders. Operations that do not fit create, read, update or delete are often modelled as a sub-resource or a state change.
Pattern 2: Use HTTP Methods and Status Codes Correctly
4 entriesLet each method keep its meaning: GET reads and is safe, POST creates or triggers processing, PUT replaces, PATCH changes part of a resource and DELETE removes it. Return status codes that say what happened, such as 201 with a Location header after creation and 404, 409 or 422 for client errors.
Pattern 3: Paginate, Filter and Sort Collections
3 entriesNever return an unbounded list. Cursor-based pagination stays stable when records are added or removed, while offset pagination is simpler but can skip or repeat items. Return the next page as a link, and expose filters and sort order as query parameters.
Pattern 4: Return Consistent Error Responses
2 entriesUse one error shape across the whole API so clients can handle failures generically. RFC 9457 defines a machine-readable problem details format with a type, title, status, detail and instance.
Pattern 5: Make Writes Idempotent and Retries Safe
2 entriesNetworks fail, so clients retry. GET, PUT and DELETE are idempotent by definition, but POST is not, so APIs accept a client-supplied Idempotency-Key and return the original result when the same key arrives again.
Pattern 6: Version and Deprecate Deliberately
3 entriesPlan for change from the start. Version in the URL, in a header or by date, announce deprecation with the Deprecation header and give the removal date in a Sunset header.
Pattern 7: Cache Responses and Rate-Limit Clients
5 entriesLet clients and proxies reuse responses with Cache-Control and ETag validators, so unchanged data returns a cheap 304. Protect the service with rate limits that answer 429 Too Many Requests and tell clients when to retry.
Pattern 8: Describe the Contract Machine-Readably
2 entriesPublish the API as a machine-readable contract. An OpenAPI description lists endpoints, parameters and schemas, and tools use it to generate documentation, client SDKs, mock servers and contract tests.
Related Pages
5 entriesRelated directories on this site.
Frequently Asked Questions
What is a REST API?
REST is an architectural style defined by Roy Fielding in which clients interact with named resources through a uniform interface. In everyday use, a REST API is an HTTP API that exposes resources as URLs and usually exchanges JSON.
Should REST API URLs contain verbs?
Generally no. The URL should name the resource, such as /orders/{id}, and the HTTP method supplies the action. Operations that are not simple create, read, update or delete are often modelled as a sub-resource or a state change.
What is the difference between PUT, PATCH and POST?
PUT replaces a resource with the full representation sent and is idempotent. PATCH applies a partial change, for example in JSON Merge Patch or JSON Patch format. POST creates a resource or triggers processing and is not idempotent by default.
Should I use cursor or offset pagination?
Offset pagination is simple but can skip or repeat items when data changes between requests. Cursor pagination is more stable and scales better on large collections, so many public APIs use it.
How should a REST API return errors?
Use the right HTTP status code and a consistent body. RFC 9457 defines the problem details format, with fields such as type, title, status, detail and instance, so clients can parse every error the same way.