0

There is a third party application who is storing the details of all employee of our system. The attributes of employee are id, name, address and age.

I have to design a REST application to communicate with that service. So I will receive a request from UI - create/update/delete employee which I will further send to that third party application with information.

In case of creating a new employee, I have POST end point in which I receive employee data in post body. I will further send this data to third party application to store.

Now lets say I want to update the address of the employee. In this case I will receive employee id and new address from UI which I need to further send it to third party application to update. So my application end point should be PUT or PATCH in this case ?

  • 1
    [Use of PUT vs PATCH methods in REST API real life scenarios](https://stackoverflow.com/questions/28459418/use-of-put-vs-patch-methods-in-rest-api-real-life-scenarios) – Giri Oct 15 '20 at 16:01
  • As a rule of thumb: PUT should always contain complete resource, so you should use PATCH. Unless you consider the address as a separate resource (eg: /users/1/address), then it would be PUT. – Mafor Oct 15 '20 at 18:52
  • PATCH is an HTTP method specifically designed for partial updates to a resource and only modified values are sent instead of all of the fields which is significantly good to reduce bandwidth. POST is a more generic HTTP method that is commonly used for creating new resources. While it can also be used for updating resources, it typically implies a complete replacement of the resource rather than a partial update. When using POST for updates, you would typically need to send the entire resource, including the unchanged fields, which can be inefficient in comparison to PATCH. – Rode093 Jun 14 '23 at 18:00

0 Answers0