Making authenticated HTTP PATCH requests with Postman

Now, we will use one of the GUI tools we installed in Chapter 1, Installing the Required Software and Tools, specifically, Postman. We will use this GUI tool to compose and send an HTTP PATCH request with the appropriate authentication credentials to the web service. In the previous chapters, whenever we worked with Postman, we didn't specify authentication credentials.

We will use the Builder tab in Postman to compose and send an HTTP PATCH request to update the has_it_competed field for the previously created drone. Follow these steps:

  1. In case you made previous requests with Postman, click on the plus (+) button at the right-hand side of the tab that displayed the previous request. This way, you will create a new tab.
  2. Select PATCH in the drop-down menu at the left-hand side of the Enter request URL textbox.
  3. Enter http://localhost:8000/drones/12 in that textbox at the right-hand side of the drop-down. Replace 12 with the ID generated for the previously created drone in your configuration.
  4. Click the Authorization tab below the textbox.
  5. Select Basic Auth in the TYPE drop-down.
  6. Enter the name you used to create djangosuper in the Username textbox.
  7. Enter the password you used instead of passwordforsuper for this user in the Password textbox. The following screenshot shows the basic authentication configured in Postman for the HTTP PATCH request:
  1. Click Body at the right-hand side of the Authorization and Headers tabs, within the panel that composes the request.
  2. Activate the raw radio button and select JSON (application/json) in the drop-down at 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.
  3. Enter the following lines in the textbox below the radio buttons, within the Body tab:
   { 
       "has_it_competed": "true" 
   }

The following screenshot shows the request body in Postman:

We followed the necessary steps to create an HTTP PATCH request with a JSON body that specifies the necessary key/value pairs to update the value for the was_included_in_home field of an existing drone, with the necessary HTTP authentication credentials. Click Send and Postman will display the following information:

  • Status: 200 OK
  • 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 updated drone formatted as JSON with syntax highlighting

The following screenshot shows the JSON response body in Postman for the HTTP PATCH request. In this case, the request updated the existing drone because we authenticated the request with the user that is the drone's owner:

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

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