Updating a single field for a resource with the PATCH method
Due to the usage of generic class-based views, our API is able to update a single field for an existing resource, and therefore, we provide an implementation for the PATCH
method. For example, we can use the PATCH
method to update an existing game and set the value for its played_once
and played_times
field to True
and 1
. We don't want to use the PUT
method because this method is meant to replace an entire game. Remember that the PATCH
method is meant to apply a delta to an existing game, and therefore, it is the appropriate method to just change the value of the played_once
and played_times
fields.
Now we will compose and send an HTTP PATCH
request to update an existing game, specifically, to update the value of the played_once
and played_times
fields and set them to True
and 10
. Make sure you replace 2
with id
of an existing game in your configuration. The code file for the sample is included in the restful_python_2_07_01
folder...