AlgoMaster Logo

Designing Update APIs

High Priority11 min readUpdated November 12, 2026
Listen to this chapter
Unlock Audio

Updating existing resources is another fundamental operation in API design. Whether a user changes their profile information, an administrator updates a product's price, or a customer modifies an order, the API needs to apply changes safely and predictably.

At first glance, updating a resource seems simple. The client sends new values, and the server saves them.

But several important questions arise.

Should the client send the entire resource or only the fields that changed? What happens to fields that are omitted? How do we prevent two clients from accidentally overwriting each other's changes? And what happens if an update request is retried after a network failure?

A well-designed Update API needs clear answers to these questions.

In this chapter, we'll explore how to design reliable Update APIs using our Bookstore API as an example.

1. Understanding Update Operations

Suppose our bookstore contains the following book:

Now imagine an administrator wants to change its price from $45 to $40.

The API needs to identify the resource, accept the updated information, validate the requested change, and persist it.

In REST APIs, updates generally target an individual resource:

The resource identifier belongs in the URL because we're modifying an existing book.

The HTTP method determines how the update should be interpreted.

Two methods are commonly used:

  • PUT replaces the resource's representation with the one supplied by the client.
  • PATCH applies a set of changes to an existing resource.

Both methods are useful, but they have different semantics.

2. Updating Resources with PUT

The PUT method is generally used when the client wants to replace the current representation of a resource.

For example:

The client sends the complete set of client-writable fields, including those that haven't changed.

PUT represents the desired new state rather than a list of differences, so a field the client omits may be cleared or reset to its default. For partial modifications, PATCH is generally the clearer choice.

3. Updating Resources with PATCH

What if the administrator only wants to change the price?

Sending the entire book representation would be unnecessary.

Instead, the API can support PATCH.

For example, using JSON Merge Patch:

The server applies the requested change while preserving the other fields.

This approach is convenient for user interfaces where clients typically modify only a few fields at a time.

PATCH doesn't prescribe a single request format, though. Common choices include JSON Merge Patch, JSON Patch, which expresses changes as explicit operations such as add, remove, replace, and test, and custom JSON update schemas.

4. Defining Update Semantics Clearly

One of the most important decisions in Update API design is defining what each field means when it appears, disappears, or contains null.

In a partial update, an omitted field normally stays unchanged, but what an explicit null means depends on the update format.

The flowchart below shows how a JSON Merge Patch request treats the description field in each of the three cases.

Omitting the field leaves it alone, while sending null removes it under Merge Patch rules. A custom PATCH format may choose different rules, and the documentation should state them just as plainly.

Immutable and server-controlled fields

Not every field should be updateable.

For example, our bookstore might prevent changes to:

  • id, because it uniquely identifies the resource.
  • created_at, because it's managed by the server.
  • created_by, because it should reflect the original creator.

Some business fields may also become immutable after creation.

For example, an order's customer ID might not be changeable once the order has been placed.

A good Update API explicitly defines which fields can be modified and rejects attempts to update restricted fields.

5. Validating Update Requests

Updates require the same careful validation as creation.

Suppose an administrator submits:

The request is syntactically valid JSON, but a negative price violates our bookstore's business rules.

The server can return:

Validation should cover both individual fields and relationships between fields.

For example, imagine that a book can have the statuses draft, published, and archived.

The application might allow transitions from draft to published, but prohibit direct changes from archived back to draft.

These rules need to be enforced on the server.

6. Choosing the Right Response

When an update succeeds, there are two common response patterns.

200 OK with updated resource

The server can return the updated representation:

This is useful when the server applies normalization, calculates fields, or updates timestamps.

The client immediately receives the final resource state.

204 No Content

Alternatively, the server can return:

This indicates that the update succeeded, but there is no response body.

It's a good choice when the client doesn't need the updated representation.

Both approaches are valid. Choose one based on how clients consume the API, and remain consistent across similar endpoints.

For failures, common responses include 400 or 422 for invalid requests, 404 for missing resources, 403 for insufficient permissions, and 409 for business-state conflicts.

7. Preventing Lost Updates

One of the most important challenges in Update API design is handling concurrent modifications.

Imagine two administrators, Alice and Bob, viewing the same book.

The book currently costs $45.

Alice changes the price to $40, while Bob changes the description.

Both originally loaded the same resource.

If Bob sends a full replacement after Alice's update, his old representation might still contain the $45 price.

As a result, Bob's update could accidentally overwrite Alice's change.

This is known as the lost update problem.

Optimistic concurrency control

A common solution is optimistic concurrency control. The client sends the ETag it received with the resource in an If-Match header:

If another client has changed the book since then, the server rejects the update with 412 Precondition Failed instead of overwriting the newer data.

The sequence below replays the Alice and Bob scenario with ETags in place.

GET /v1/books/book_789200 OK, ETag book-789-v5GET /v1/books/book_789200 OK, ETag book-789-v5PATCH price_cents 4000, If-Match book-789-v5200 OK, new versionUpdate with If-Match book-789-v5412 Precondition FailedGET latest, then retry with new ETagAliceBooks APIBobAliceBooks APIBob
9 / 9
algomaster.io

Both administrators start from version v5. Alice's update succeeds and bumps the version, so Bob's request carrying the old ETag fails with 412 instead of overwriting her price change.

8. Idempotency and Retries

Update APIs also need predictable retry behavior.

PUT is idempotent by definition, but whether a PATCH is idempotent depends on the patch document. Setting the price to $40 twice has the same effect as setting it once, while an increment_by operation applied twice increments the value twice. When retries could accidentally repeat business operations, consider conditional requests, version checks, or idempotency keys.

Also avoid unnecessary side effects when the same update is retried. For example, a retry should not automatically send duplicate notifications or trigger duplicate billing operations.

9. Atomicity and Partial Failures

Suppose a client sends an update that modifies both the price and status of a book.

What happens if updating the price succeeds but updating the status fails?

For an ordinary single-resource PATCH operation, the changes should be applied atomically.

Either the entire update succeeds, or none of its changes are committed.

If the resource is stored in a relational database, this can often be implemented using a database transaction.

Atomicity is especially important when multiple fields must remain consistent with each other.

For updates spanning multiple independent services, atomic execution becomes more complicated. Such workflows may require coordination, asynchronous processing, or compensating actions.

Avoid silently reporting a successful update when only part of a single-resource modification was applied.

10. Authorization and Security

An Update API must verify that the caller has permission to modify the requested resource.

For example:

The server should check whether the authenticated user is allowed to edit that book.

Authorization may also depend on individual fields.

A bookstore administrator might be allowed to change a book's description but not its financial or inventory information.

These restrictions must be enforced on the server, even if the frontend hides the corresponding input fields.

Never blindly copy arbitrary request fields into database models.

Explicitly allow supported update fields and reject unauthorized changes.

Key Takeaways

Designing a good Update API requires more than accepting new values and writing them to a database.

Use PUT when clients provide a replacement representation and PATCH when they need to apply partial modifications. Clearly define the behavior of omitted fields, null values, and immutable properties.

Validate the resulting resource, enforce authorization, and use appropriate HTTP status codes.

For concurrent modifications, consider optimistic concurrency control using ETags or resource versions. For operations that may be retried, understand whether the update is idempotent.

Most importantly, ensure that updates are predictable, atomic where required, and safe under real-world conditions such as concurrent requests and network failures.

A well-designed Update API allows clients to modify resources confidently without accidentally losing data or introducing inconsistent state.

Quiz

Designing Update APIs Quiz

10 quizzes