x Share your thoughts on trends and content!

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

by Jonathan Allen on Jun 20, 2008 |

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


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

General Feedback
Marketing and all content copyright © 2006-2016 C4Media Inc. hosted at Contegix, the best ISP we've ever worked with.
Privacy policy

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.