PUT or PATCH

I’ve been a part of a number of conversations where people are fighting for PUT while others are very sure of PATCH. Anyway, here’s the PUT RFC. Here’s the PATCH RFC. I think the PATCH RFC is very clear – Straight from RFC 5789:

The difference between the PUT and PATCH requests is reflected in the
way the server processes the enclosed entity to modify the resource
identified by the Request-URI. In a PUT request, the enclosed entity
is considered to be a modified version of the resource stored on the
origin server, and the client is requesting that the stored version
be replaced. With PATCH, however, the enclosed entity contains a set
of instructions describing how a resource currently residing on the
origin server should be modified to produce a new version. The PATCH
method affects the resource identified by the Request-URI, and it
also MAY have side effects on other resources; i.e., new resources
may be created, or existing ones modified, by the application of a
PATCH.

TL;DR

Think of a PUT as a modification of the whole resource. While PATCH aims to modify parts of the resource, and not necessarily the whole resource.
Side note, a PATCH operation may have side effects on other resources.
Learned this part, today.

This entry was posted in Technical stuff. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.