Http PUT And PATCH
Http PUT:
Use for update the record, if exist update the whole object and if not exist create new object.
Let's say we have employee object with following property
empId
firstName
lastName
department
dob
And if you want to update existing object with new property irrespective of what we have existing value.
In this case you will use PUT method with following
{
"empId":"102",
"firstName":"first",
"lastName":"last",
"department":"computer",
"dob":"2012-10-22"
}
This will overwrite the existing object with new one and if not exist create new one.
Http PATCH:
If you are sure that object exist and you want only update the firstName in this case we will use PATCH method and will pass only property that we want to update
{
"empId":"102",
"firstName":"first"
}
In case object does not exist this operation will fail.
Labels: difference put and patch, Http PATCH method, Http PUT method, PUT Vs PATCH
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home