HTTP Methods: PUT vs PATCH

Rapid
HTTP Methods: PUT vs PATCH
HTTP Methods: PUT vs PATCH

HTTP Methods: PUT vs PATCH

Rapid
HTTP Methods: PUT vs PATCH
HTTP Methods: PUT vs PATCH

APIs use several HTTP Methods to create, read, update, and delete data. Two of these methods - PUT and PATCH are used to update and modify data. However, they both do this in slightly different ways. To summarise their difference, we can say that PUT uses the request URI to deliver a modified version of the resource that completely replaces the original. On the other hand, PATCH only partially updates a resource without needing to modify the entire resource.

Rapid
HTTP Methods: PUT vs PATCH
HTTP Methods: PUT vs PATCH

The PUT method works by completely replacing the original resource with the updated version. If the resource already exists, PUT replaces it. If it does not exist, PUT creates it.

Rapid
HTTP Methods: PUT vs PATCH
HTTP Methods: PUT vs PATCH

Alternatively, PATCH applies partial updates to resources. The client only needs to send the data intended to be modified in the payload of the request and the rest of the resource remains unchanged. Since PATCH requests typically send minimal data that simply 'patches' a resource, it uses less bandwidth than PUT.

Rapid
HTTP Methods: PUT vs PATCH
HTTP Methods: PUT vs PATCH

In general, it's best to use PUT only when a whole resource requires updating. Using PUT to update only a few, or even just a single field of a resource often uses unnecessary bandwidth.