put vs patch rest call difference with example?

mallikharjunasw
Tera Contributor

put vs patch rest call difference with example?

5 REPLIES 5

Pratiksha Kalam
Kilo Sage

Hi,

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.

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;

 

If my answer is worthy,mark it as correct and helpful.

Regards,

Pratiksha

Aleksas Kucins1
Giga Expert

Hi,

 

There are no differences in ServiceNow between PATCH and PUT.

 

https://hi.service-now.com/kb_view.do?sysparm_article=KB0534905

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Mallikharjuna,

see below links and it should be helpful

https://hi.service-now.com/kb_view.do?sysparm_article=KB0534905

https://community.servicenow.com/community?id=community_question&sys_id=229a832ddb5cdbc01dcaf3231f96...

https://community.servicenow.com/community?id=community_question&sys_id=fd48ad43db8b6b00afc902d5ca96...

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Mallikharjuna,

Any update on this?

Can you mark my answer as correct, helpful if you were able to achieve the requirement and close the thread

Regards

Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader