官术网_书友最值得收藏!

  • Cloud-Native Applications in Java
  • Ajay Mahajan Munish Kumar Gupta Shyam Sundar
  • 119字
  • 2021-06-24 19:07:16

Testing the service on the browser

Open a browser and hit the following URL: http://localhost:8080/product/1.

You should get back the following response:

{"id":1,"name":"Oranges ","catId":2}

Now, try the other service (URL—http://localhost:8080/productIds). What response do you get? An error, as follows:

    There was an unexpected error (type=Bad Request, status=400).
    Required int parameter 'id' is not present

Can you guess why? It is because the service definition that you wrote had a method expecting a request parameter:

@RequestMapping("/productIds")
List<Integer> getProductIds(@RequestParam("id") int id) {

So, the URL is expecting an id and as you did not supply it, it gives an error.

Give the parameter and try  http://localhost:8080/productIds?id=5 again.

You will now get back a correct response:

[6,7,8]
主站蜘蛛池模板: 乌苏市| 漯河市| 台中市| 图木舒克市| 宁陕县| 阿鲁科尔沁旗| 于田县| 辽宁省| 阜南县| 铅山县| 南召县| 桑植县| 江门市| 许昌县| 县级市| 普定县| 巴青县| 大竹县| 汝阳县| 金沙县| 鲁山县| 磐安县| 兰西县| 上林县| 延寿县| 江华| 牟定县| 徐闻县| 乡宁县| 林芝县| 红河县| 山东省| 鹤庆县| 和龙市| 乌鲁木齐市| 衡阳市| 普洱| 望城县| 漳州市| 贺兰县| 长宁区|