API / Web services
Difference between PUT and PATCH HTTP methods.
PUT is considered idempotent. When you PUT a resource, these two assumptions are in play:
- You are referring to an entity, not to a collection.
- The entity you are supplying is complete (the entire entity).
The PUT includes all of the parameters on the entity, but PATCH only includes the one that was being modified. See the below example, create a user using POST:
POST /users/1 { "username": "javapedia", "email": "user1@javapedia.net" }
If you want to modify this entity later, you choose between PUT and PATCH. A PUT might look like this:
PUT /users/1 { "username": "javapedia", "email": "user123@javapedia.net" //new email ID }
The same update using PATCH look like this:
PATCH /users/1 { "email": "user123@javapedia.net" //new email ID }
When using PUT, it is assumed that you are sending the complete entity, and that the complete entity replaces any existing entity at that URI. In the above example, the PUT and PATCH accomplish the same goal: they both change this user's email address. But PUT handles it by replacing the entire entity, while PATCH only updates the fields that were supplied, leaving the others alone. So PUT is considered idempotent however PATCH is not.
More Related questions...