Working with GUI tools - Postman and others

So far, we have been working with two terminal-based or command-line tools to compose and send HTTP requests to our Django development server: cURL and HTTPie. Now, we will work with one of the GUI tools we used when composing and sending HTTP requests to the Flask development server in Chapter 1, Developing RESTful APIs and Microservices with Flask 1.0.2. In case you skipped this chapter, make sure you check the installation instructions in the section named Working with GUI tools - Postman and others.

Once you launch Postman, make sure you close the modal that provides shortcuts to common tasks. Select the GET request in the + new drop-down menu in the upper-left corner of the Postman main window.

Select GET in the drop-down menu on the left-hand side of the Enter request URL textbox, and enter http://localhost:8888/leds/3 in the textbox on the right-hand side of the drop-down menu.

Then, 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 response size calculated by adding the body size to the headers size.
  • Body: The response body with all the notifications formatted as JSON with syntax highlighting. The default view for the response body is the pretty view, and it activate syntax highlighting that makes it easy to read JSON code.

The following screenshot shows the JSON response body in Postman for the HTTP GET request to localhost:8888/leds/3:

Click on the Headers (5) tab at the right-hand side of the Body and Cookies tabs to read the response headers. The following screenshot shows the layout for the response headers that Postman displays for the previous response. Notice that Postman displays the Status on the right-hand side of the response, and doesn't include it as the first line of the headers, as happened when we worked with both the curl and http command-line utilities:

Now, we will compose and send an HTTP request to update the brightness level for an LED, specifically an HTTP PATCH request. Follow these steps:

  1. Click on the plus (+) button on the right-hand side of the tab that showed the previous request. This way, you will create a new tab.
  2. Select PATCH in the drop-down menu on the left-hand side of the Enter request URL textbox, and enter http://localhost:8888/leds/3 in this textbox at the right-hand side of the drop-down.
  3. Click Body at the right-hand side of the Authorization and Headers tabs, within the panel that composes the request.
  4. 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 that there is one key-value pair specified for the request headers.
  5. Enter the following lines in the textbox below the radio buttons, in the Body tab. The code file for the sample is included in the restful_python_2_10_01 folder, in the Tornado01/cmd/cmd1111.txt file:
{ 
    "brightness_level": 64 
} 

The following screenshot shows the request body in Postman:

We followed the steps necessary to create an HTTP PATCH request with a JSON body that specifies the necessary key-value pairs to set the new brightness level for the LED whose id is equal to 3. Click Send and Postman will display Status (200 OK), the time it took for the request to be processed, and the response body with the recently added game formatted as JSON with syntax highlighting (pretty view). The following screenshot shows the JSON response body in Postman for the HTTP PATCH request in the Body tab:

The Tornado HTTP server is listening on every interface on port 8888, and therefore we can also use apps that can compose and send HTTP requests from mobile devices to work with the RESTful API. For example, we can work with the previously introduced iCurlHTTP app on iOS devices, such as the iPad Pro and iPhone. On Android devices, we can work with the previously introduced HTTP Request app.

The following screenshot shows the results of composing and sending the following HTTP request with the iCurlHTTP app: GET http://192.168.1.101:8888/leds/2. Remember that you have to perform the previously explained configurations on your LAN and router to be able to access the Flask development server from other devices connected to your LAN. In this case, the IP assigned to the computer running the Tornado HTTP server is 192.168.1.101, and therefore you must replace this IP with the IP assigned to your development computer:

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

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