The PUT method is used to update an existing resource on the server. The request should include the resource's unique identifier (such as an id
) and the updated data in the request body. The server processes this data and replaces the existing resource.
The headers
property specifies metadata about the request. In this case, "Content-Type": "application/json"
informs the server that the body of the request contains JSON data.
Body
The body
property contains the data being sent to the server. The JSON.stringify()
method converts the JavaScript object into a JSON string, which is required by the server to process the incoming data properly.
Key-Value Pairs in the Body
The id
identifies the resource being updated on the server, such as a specific blog post or task. The title
and body
are custom attributes representing the updated content for the resource, while the userId
links the updated resource to a specific user. These key-value pairs in the body are custom attributes defined to align with the given API endpoint's requirements to make sure the data is updated successfully.