The PATCH Method
We have been using the PUT
HTTP method all along for data updates. However, the actual usage of the PUT
method is to Replace (Create or Update). For example, PUT /items/1
means to replace everything in /items/1
. If this item already exists, it will be replaced. Otherwise, it will create a new item. PUT
must contain all attribute data for items/1
.
This doesn't seem to work very well in all cases. If you just want to update only one of the attributes of items/1
, you need to retransmit all the attributes of items/1
to the server, which is not efficient at all. So, there is a new HTTP method: PATCH. The PATCH
method was invented to do a partial update. With this method, we need to pass in only the attributes that need to be modified to the server.
Exercise 37: Using the PATCH Method to Update the Recipe
In this exercise, we will change the recipe update method from PUT
to PATCH
. We will also use the serialization/deserialization approach to transmit the recipes...