levelup.gitconnected.com 4 min read Original Source

8 REST API Patterns That Separate Good APIs From Great Ones

Most REST APIs don’t fail because they broke some technical rule. They fail because developers can’t predict how they behave.

Here are 8 patterns that fix thatand make your API easier to understand, integrate, and maintain.

1. Design Around Resources, Not Actions

A common mistake: endpoints like getUsers, createOrder, deleteProduct.

They look fine at first. But the URL is now describing the action, while HTTP already does that job.

The cleaner fix is, treat users, orders, and products as resources. Let GET, POST, and DELETE describe the operation.

list orders
POST /orders -> create an order
GET /orders/{id} -> retrieve an order
PUT /orders/{id} -> replace an order
DELETE /orders/{id} -> delete an order” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

GET    /orders        -> list orders
POST   /orders        -> create an order
GET    /orders/{id}   -> retrieve an order
PUT    /orders/{id}   -> replace an order
DELETE /orders/{id}   -> delete an order
GET    /orders        -> list orders
POST   /orders        -> create an order
GET    /orders/{id}   -> retrieve an order
PUT    /orders/{id}   -> replace an order
DELETE /orders/{id}   -> delete an order

This scales better too. The same resource supports multiple operations without inventing a new URL for each one.

The rule: the URL identifies the resource. The HTTP method describes what you’re doing to it.

2. Make Your URLs Predictable

Imagine one part of your API uses /user, another uses /customers, another uses /customer-profiles.

Each endpoint might work fine on its own. But now every developer has to memorize your naming rules.

A better API sticks to one structure. Collections get consistent names, users, orders, products. Specific resources are accessed by ID.

Pick one convention for multi-word resources and use it everywhere. The exact convention matters less than the consistency.

3. Use HTTP Methods for Their Actual Purpose

You need to update a user. One API uses POST. Another uses PUT. A third uses PATCH.

All three might “work.” But now every client has to learn your custom rules instead of trusting standard HTTP.

Here’s what each method actually means:

  • GET — retrieve data, no side effects
  • POST — create a resource, or trigger a process that isn’t a simple update
  • PUT — replace a resource’s representation
  • PATCH — partial update
  • DELETE — remove a resource

updates just the email, nothing else

PUT /users/42
{ "name": "…", "email": "…", "role": "…" }
-> replaces the whole user record” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>

PATCH /users/42
{ "email": "[email protected]" }
   -> updates just the email, nothing else

PUT /users/42
{ "name": "...", "email": "...", "role": "..." }
   -> replaces the whole user record
PATCH /users/42
{ "email": "[email protected]" }
   -> updates just the email, nothing else

PUT /users/42
{ "name": "...", "email": "...", "role": "..." }
   -> replaces the whole user record

Underneath this sits a bigger idea: idempotency. Fire the same GET, PUT, or DELETE five times, and the result should look the same as firing it once.

POST breaks that rule on purpose. Send the same “create” request twice, and you may end up with two resources instead of one.

Why it matters: networks fail, clients retry, timeouts happen. Pick your method by what it means, not by whatever happens to make the endpoint run.

4. Make Status Codes Actually Useful

Here’s a response that causes real problems: HTTP status 200, but the response body says the operation failed because the product wasn’t found.

Now the client has to check two different places to know what actually happened.

Use the status code to carry the real result a 2xx for success, a 4xx when the client got something wrong, a 5xx when your server did. The MDN HTTP status code reference is the full list, and it’s worth bookmarking rather than memorizing.

You don’t need to memorize every code. You need the status code to tell the truth about what happened without inventing your own error protocol on top of HTTP.

5. Keep Errors Consistent

A status code tells you the category of failure. Clients usually need more.

Compare this:

{ "error": "Something went wrong" }
{ "error": "Something went wrong" }

To this:

{
  "code": "PRODUCT_NOT_FOUND",
  "message": "No product exists with the given ID",
  "status": 404
}
{
  "code": "PRODUCT_NOT_FOUND",
  "message": "No product exists with the given ID",
  "status": 404
}

The second version is far easier to work with. The client can show the message, the app can react to the code, and developers can actually debug the problem.

For validation errors, go a step further — return exactly which fields failed, not just “invalid request.” The exact format can vary. What matters is that it’s structured and predictable, every time.

6. Don’t Cram Everything Into the URL Path

You start with /products. Then you add category to the path. Then stock status. Then price. Then search. Then sorting.

Eventually the URL becomes unmanageable.

Filtering and optional criteria belong in query parameters, not the path:

GET /products?category=shoes&inStock=true&sort=price
GET /products?category=shoes&inStock=true&sort=price

The path identifies the resource. The query parameters refine the result.

One thing to avoid: don’t use query parameters to fake actions. A GET request with ?action=delete is confusing. The method no longer tells the truth about what’s happening.

Paths identify resources.

Query parameters refine them.

Methods describe the operation.

7. Handle API Changes Carefully

APIs don’t stay frozen forever. A response that’s perfect today might need to change in six months.

The dangerous move is making a breaking change without thinking about the clients already depending on you.

Say an earlier version returns a flat price field, and you want to move to a richer pricing object. That’s not “just another field” the structure changed, and existing clients can break.

Before reaching for a new version, ask: does this actually need one?

  • Adding a non-required field -> usually safe
  • Changing or removing existing behavior -> usually not

When you do need to version, make the strategy obvious and consistent, a version in the URL, a header, whatever fits. The specific mechanism matters less than picking one and giving consumers a migration path.

Good API evolution means existing clients don’t become collateral damage.

8. Keep Request and Response Formats Consistent

One endpoint returns created_at. Another returns createdAt. A third returns date_created.

Each one is valid JSON. But now every client has to remember which convention applies to which endpoint.

The same problem shows up with dates, pagination, error shapes, and property naming across your whole API.

Pick your conventions once and hold the line:

  • One JSON style throughout
  • One naming convention for properties
  • One error response shape
  • One pattern for pagination and filtering

The goal isn’t a giant rulebook. It’s that the next endpoint feels familiar. Once a developer learns one part of your API, they should be able to guess the rest correctly.

Consistency is one of the best features an API can have.

The Real Goal Isn’t “Being RESTful”

A lot of developers optimize for whether their API technically follows REST. That’s useful but it’s not the point. Your API doesn’t become good just because it uses GET, POST, PUT, and DELETE correctly.

A good API is one clients can understand without constantly checking the docs.

Resource names make sense. Methods behave predictably. Status codes mean something. Errors are structured. Filters work the same way everywhere. And changes don’t quietly break the people depending on you.

So before you build your next REST API, don’t start writing endpoints one at a time. Start by answering the bigger questions:

How will you name resources? How will collections work? How will filtering behave? Which HTTP methods will you actually use? How will errors look? How will status codes be handled? How will the API evolve?

Once those answers are clear, building the API is the easy part.

A good REST API doesn’t just return the right data it makes the right way to use it obvious.