- Mastering Microservices with Java
- Sourabh Sharma
- 347字
- 2021-07-02 13:03:33
Testing using Postman
This book uses the Postman tool for REST service testing. I have used the 6.2.5 version of Postman.
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 the 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 view 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:

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. This returns the following JSON:
{ "function": "power", "input": [ "2", "4" ], "output": [ "16.0" ] }
This returns the preceding JSON with a response status of 200 OK, as shown in the following screenshot:

- Mastering OpenLayers 3
- ClickHouse性能之巔:從架構設計解讀性能之謎
- Mastering NetBeans
- Beginning Java Data Structures and Algorithms
- 手把手教你學C語言
- H5頁面設計:Mugeda版(微課版)
- Swift細致入門與最佳實踐
- SQL Server 2008 R2數據庫技術及應用(第3版)
- Python大學實用教程
- C指針原理揭秘:基于底層實現機制
- 深入淺出Python數據分析
- Mastering Apache Camel
- MySQL數據庫應用實戰教程(慕課版)
- 深度學習的數學:使用Python語言
- iOS應用逆向工程:分析與實戰