Making HTTP POST requests with Postman

Now, we will use the Builder tab in Postman to compose and send an HTTP POST request to create a new toy. Perform the following steps:

  1. Click on the plus (+) button on the right-hand side of the tab that displayed the previous request. This way, you will create a new tab.
  2. Select Request in the New drop-down menu located in the upper-left corner.
  3. Select POST in the drop-down menu on the left-hand side of the Enter request URL textbox.

 

  1. Enter localhost:8000/toys/ in that textbox on the right-hand side of the drop-down menu.
  2. Click Body on the right-hand side of Authorization and Headers, within the panel that composes the request.
  3. Activate the raw radio button and select JSON (application/json) in the drop-down menu on the right-hand side of the binary radio button. Postman will automatically add a Content-type = application/json header, and therefore, you will notice the Headers tab will be renamed to Headers (1), indicating to us that there is one key-value pair specified for the request headers.
  4. Enter the following lines in the textbox below the radio buttons, within the Body tab:
{ 
    "name": "Wonderboy puzzle",  
    "description":"The Dragon's Trap puzzle", 
    "toy_category":"Puzzles & Games", 
    "was_included_in_home": "false", 
    "release_date": "2017-10-03T01:01:00.776594Z" 
} 

The following screenshot shows the request body in Postman:

We followed the necessary steps to create an HTTP POST request with a JSON body that specifies the necessary key-value pairs to create a new toy. Click Send and Postman will display the following information:

  • Status: 201 Created
  • Time: The time it took for the request to be processed
  • Size: The approximate response size (sum of body size plus headers size)
  • Body: The response body with the recently added toy formatted as JSON with syntax highlighting

The following screenshot shows the JSON response body in Postman for the HTTP POST request:

If we want to compose and send an HTTP PUT request with Postman, it is necessary to follow the previously explained steps to provide JSON data within the request body.

One of the nice features included in Postman is that we can easily review and run the HTTP requests we have made again by browsing the saved History shown on the left-hand side of the Postman window. The History panel displays a list with the HTTP verb followed by the URL for each HTTP request we have composed and sent. We just need to click on the desired HTTP request and click Send to run it again. The following screenshot shows the many HTTP requests in the History panel and the first HTTP GET request that was executed selected so it can be easily resent:

..................Content has been hidden....................

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