Cloud-Native Applications in Java
上QQ阅读APP看书,第一时间看更新

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]