Executing the POST service

To create a new Todo using POST, we would need to include the JSON for the Todo in the body of the request. The following screenshot shows how we can use the Postman app to create the request and the response after executing the request:

A few important things to note are as follows:

  • We are sending a POST request. So, we choose the POST from the top-left dropdown.
  • To send the Todo JSON as part of the body of the request, we select the raw option in the Body tab (highlighted with a blue dot). We choose the content type as JSON (application/json).
  • Once the request is successfully executed, you can see the status of the request in the bar in the middle of the screen: Status: 201 Created.
  • The location is http://localhost:8080/users/Jack/todos/5. This is the URI of the newly created todo that is received in the response.

Complete details of the request to http://localhost:8080/users/Jack/todos are shown in the block, as follows:

    Header
Content-Type:application/json

Body
{
"user": "Jack",
"desc": "Learn Spring Boot",
"done": false
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset