What is the need for the PUT Method if we can update the whole resource in the PATCH request itself?

277 Views Asked by At

If we pass all the fields of the resource in a PATCH request's body, it would overall act as a PUT request itself, i.e. update the whole resource. So what is the need for the PUT method?

1

There are 1 best solutions below

0
VoiceOfUnreason On

PUT has stronger semantic guarantees than PATCH.

PUT is idempotent

A request method is considered idempotent if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request.

If general purpose HTTP connectors know that a request has idempotent semantics, then they can do intelligent things with that information. For instance, on an unreliable network, a general purpose component can retry a PUT request if it times out waiting for a response.

PATCH, like POST, is not so tightly constrained; retrying a request isn't guaranteed to be risk free.