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

Sandeep Rajput
Tera Patron
Tera Patron

@shabbir5 Please refer to https://apidog.com/blog/put-vs-post/ to know the difference. 

 

In a nut shell, put is used to create new record and patch is used for updating an existing record. Hope this answers your question.

Hi @Sandeep Rajput ,

 

Any idea how we can show the difference by using REST API EXPLORER ?

 

Thank you,

Shabbir Shaik

@shabbir5 You can create a new record using the Put method and update an existing using patch this is the usual way you can show the difference.

 

Please mark my response helpful and accepted solution if it addresses your question.

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