Merge, Replace, or Patch: How Astoria Handles Changing Data

| by Jonathan Allen Follow 499 Followers on Jun 20, 2008. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

Using REST, what should happen when you perform a PUT operation to update existing data? The Astoria Team asks that question and explains their answer.

When an Astoria-based web service receives a PUT operation, there are two possible ways to handle the update. Either it could replace the pre-existing data or it could merge the new values into the old ones. Due to their goal of maintaining compatibility with AtomPub, Microsoft decided that PUT should map to a replace.

This of course leaves the question of how to represent merging operations. Options include introducing a new verb, MERGE, or a new custom header. Pablo Castro writes,

While we’re not thrilled with the idea of introducing a new HTTP method, overloading PUT with an extra header seems to be very problematic. If anything else, a server that does not support “merge” through headers would see PUT as a regular “replace” request and perform an operation that’s not what the client expected. Also other things break. For example, if a server sees an actual MERGE request and cannot handle it then it can respond with 405 – method not supported.

Another option they considered was the PATCH operation. Unfortunately the specification wasn't finalized before Microsoft's code freeze date. This left Microsoft in the unenviable position of either using PATCH and risking the final specification was incompatible or use MERGE with the understanding that it may be deprecated. Since the first option would result in either breaking clients or being non-compliant, they decided to go with MERGE.

Since we are on the topic of clients, one should know that .NET clients default to merge semantics. This was chosen because a .NET client may not know about all the fields on the server, and the server has no way to know which fields were intentionally blank versus which were simply unknown.

AJAX clients also default to merge semantics. And like .NET clients they have an optional parameter to indicate that replace semantics are preferred.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you