A POST request is used to send data to a server, typically to create a new resource. The data you send is included in the body of the request, and it is often in JSON format. For the server to understand the data, you must also include appropriate headers, such as specifying the content type as application/json
.
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 title
is the custom attribute representing the title of the new resource, such as a blog post or task. The body
is the custom attribute containing the main content or description of the resource. UserId
is the custom attribute linking the resource to a specific user, helping the server organize and relate the data to the user it belongs to.
These key-value pairs in the body are custom attributes defined to align with the given API endpoint's requirements. They map directly to the structure expected by the server, making sure the data can be processed successfully.