Updating fields for a resource with the PATCH method
Now we will compose and send an HTTP request to update an existing notification, specifically, to update the value of the displayed_once
and displayed_times
fields. Because we just want to update two fields, we will use the PATCH
method instead of PUT
. Make sure you replace 2
with the ID or primary key of an existing notification in your configuration. The code file for the sample is included in the restful_python_2_03_01
folder, in the Flask01/cmd307.txt
file:
http PATCH ":5000/service/notifications/2" displayed_once=true displayed_times=1
The following is the equivalent curl
command. The code file for the sample is included in the restful_python_2_03_01
folder, in the Flask01/cmd308.txt
file:
curl -iX PATCH -H "Content-Type: application/json" -d '{"displayed_once":"true", "displayed_times":1}' "localhost:5000/service/notifications/2"
The previous command will compose and send a PATCH
HTTP request with the following JSON key-value pairs:
...