The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Difference between put and patch Rest API Methods?

Community Alums
Not applicable
 
3 REPLIES 3

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Community Alums 

 

PATCH: it is used to update an existing entity with new information. You can't patch an entity that doesn't exist. You would use this when you have a simple update to perform, e.g. changing a user's name.


partially updates the resource into the server mapped by the provided data. As an example, PATCH /api/log/1 will only update properties mapped in the request body. Just like the PUT method it may include an If-Match with the ETag and in case of success 200 Ok or 202 Accepted with the new ETag value should be returned, or in case of a failure a 404 Not Found or 409 Conflict will be indicated with the same conditions as the PUT method. This about it like a partial update to a row in a table, where only some columns are affected.

 

 

PUT: it is used to set an entity's information completely. PUTting is similar to POSTing, except that it will overwrite the entity if already exists or create it otherwise. You could use a PUT to write a user to your database that may already be in it.


replaces the existing resource by the new one. As an example, PUT /api/log/1 will completely replace that resource for the new one. Optionally in the request you may include an If-Match with the ETag value to be sure you are replacing the expected version of that resource (preventing concurrency problems). In case of success, it should return a 200 Ok or 202 Accepted (async operations) with the new ETag. In case the entity does not exist, a 404 Not Found must be returned or a 409 Conflict if the version or any other value in the entity are not correct with internal server state (like referenced links). Think about it like an update to a complete row in a table;

 

Thanks and Regards

Sai Venkatesh

Harish_K07
Giga Guru

 

PATCH is used to apply partial updates to a resource, meaning that only the fields that need to be changed are sent in the request body. PUT is used to replace the entire resource with a new representation, meaning that all the fields of the resource are sent in the request body, even if they are not modified.

 

Mark as correct and helpful if it solved your query.

Regards,

Harish

Robbie
Kilo Patron
Kilo Patron

Hi @Community Alums,

 

As per SN's own support site found below:

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0534905

 

What is the difference between PUT and PATCH?
In the REST world, PUT and PATCH have different semantics. PUT means replace the entire resource with given data (so null out fields if they are not provided in the request), while PATCH means replace only specified fields.  For the Table API, however, PUT and PATCH mean the same thing.  PUT and PATCH modify only the fields specified in the request.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie