What is the exact difference between PUT and PATCH methods in REST API?

shabbir5
Tera Guru

Hi All,

 

I am using REST API EXPLORER and i selected PUT methods and selected user table and then given one sys id record

 

then i updated email value and its working --> after sending the rest call --> email id got updated in target table( user table)

 

then i did the same using PATCH -- > email id got updated

 

so now the question if both PUT and PATCH are doing the same job , then what is the difference ?

 

Please provide your inputs 

 

Thank you,

Shabbir Shaik

1 ACCEPTED SOLUTION

ShreyasK0030
Kilo Guru
  1. Consider there's a record with information like name, email, age, department, role etc.
  2. The objective is to update age for that record

PUT Method:

  • If you use the PUT method, you need to send the entire records' data in the payload even if you only want to change one field.
  • If the data populated in the age field has to be updated, the entire record's data from every field like age, department, role, name, email everything has to be sent in the payload of the PUT call to third party. If you leave out any information, it will be erased or set to default.

PATCH Method:

  • If you use the PATCH method, you can just send the new age without sending out other information of name, email, department.
  • Basically PATCH is to make partial changes for a record.

    Breakdown :
    PUT : To overwrite the entire record with the changes done at the places desired while data at rest of the places remaining unchanged
    PATCH : To make change exactly where it is intended

View solution in original post

5 REPLIES 5

Hi Shreya,

 

I got theoretical explanation its very clear , can we test the same with servicenow REST API Explorer / POSTMAN ?

 

Thank you,

Shabbir Shaik