Skip to content
Advertisement

Microservices communication with optional parameters requests

I have a room service which returns detail for rooms when requesting http://localhost:8082/room/search/byRoomChar

JavaScript

Now I want to request this @GetMapping from the booking service since this is the application gateway that users are going to interact with using the http://localhost:8081/booking/search/byRoomChar.

JavaScript

Room entity code:

JavaScript

Room repository code:

JavaScript

However, this does not work because when omitting parameters when calling the getmapping from the booking service all parameter values are turned into null because of the required=false. And this are converted into Strings inside the hard coded url.

JavaScript

How can I make a get http request with optional parameters from within the code?

Advertisement

Answer

UriComponentsBuilder can help with URI construction. It correctly handles nullable query parameters.

JavaScript

Also, following answer can be helpful: https://stackoverflow.com/a/25434451/5990117

Advertisement