- Mastering Microservices with Java 9(Second Edition)
- Sourabh Sharma
- 381字
- 2021-07-02 21:54:46
REST API testing using the Postman Chrome extension
This book uses the Postman - REST Client extension for Chrome to test our REST service. I use the 5.0.1 version of Postman. You can use the Postman Chrome application or any other REST Client to test your sample REST application, as shown in the following screenshot:

Postman - Rest Client Chrome extension
Let's test our first REST resource once you have the Postman - REST Client installed. We start the Postman - REST Client from either the Start menu or from a shortcut.
By default, the embedded web server starts on port 8080. Therefore, we need to use the http://localhost:8080/<resource> URL for accessing the sample REST application. For example: http://localhost:8080/calculation/sqrt/144.
Once it's started, you can type the Calculation REST URL for sqrt and value 144 as the path parameter. You can see it in the following screenshot. This URL is entered in the URL (enter request URL here) input field of the Postman extension. By default, the request method is GET. We use the default value for the request method, as we have also written our RESTful service to serve the request GET method.
Once you are ready with your input data as mentioned earlier, you can submit
the request by clicking the Send button. You can see in the following screenshot that
the response code 200 is returned by your sample REST service. You can find the Status label in the following screenshot to see the 200 OK code. A successful request
also returns the JSON data of the Calculation resource, shown in the Pretty tab
in the screenshot. The returned JSON shows the sqrt method value of the function key.
It also displays 144 and 12.0 as the input and output lists, respectively:

Calculation (sqrt) resource test with Postman
Similarly, we also test our sample REST service for calculating the power function. We input the following data in the Postman extension:
- URL: http://localhost:8080/calculation/power?base=2&exponent=4
- Request method: GET
Here, we are passing the request parameters base and exponent with values of 2 and 4, respectively. It returns the following JSON:
{ "function": "power", "input": [ "2", "4" ], "output": [ "16.0" ] }
It returns the preceding JSON with a response status of 200, as shown in the following screenshot:

Calculation (power) resource test with Postman
- C語言程序設計習題解析與上機指導(第4版)
- Java程序設計
- Scala程序員面試算法寶典
- Microsoft Azure Storage Essentials
- 第一行代碼 C語言(視頻講解版)
- MySQL從入門到精通(軟件開發視頻大講堂)
- OpenCV with Python By Example
- JavaScript程序設計(第2版)
- Orchestrating Docker
- Visual C++開發寶典
- Java Web開發教程:基于Struts2+Hibernate+Spring
- PHP Microservices
- C Primer Plus(第6版)中文版【最新修訂版】
- HTML5+CSS3+jQuery Mobile+Bootstrap開發APP從入門到精通(視頻教學版)
- jQuery權威指南