API : Put Vs Patch

PUT = replace the ENTIRE RESOURCE with the new representation provided (no mention of related resources in the spec from what i can see)

PATCH = replace parts of the source resource with the values provided AND|OR other parts of the resource are updated that you havenot provided (timestamps) AND|OR updating the resource effects other resources (relationships)

 

PATCH was introduced for partial resource updating. Let’s take the following JSON object example for a user:

{ “first_name”: “Claude”, “last_name”: “Elements”, “email”: “claude@cloud-elements.com”, “favorite_color”: “blue” }

If I wanted to update the favorite_color attribute via a PUT I would have to send an entire representation of the resource and just change the favorite_color. For our example object this is no big deal, but for larger more complicated objects or resources this can be tedious. With a PATCH I can merely send the following JSON:

{ “favorite_color”: “red” }

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s