I have a controller that uses RestTemplate
to get data from several rest endpoints. Since RestTemplate
is blocking, my web page is taking long time to load. In order to increase the performance, I am planning to replace all my usages of RestTemplate
with WebClient
. One of the methods I currently have that uses RestTemplate
is as below.
public List<MyObject> getMyObject(String input){
URI uri = UriComponentsBuilder.fromUriString("/someurl")
.path("123456")
.build()
.toUri();
RequestEntity<?> request = RequestEntity.get(uri).build();
ParameterizedTypeReference<List<MyObject>> responseType = new ParameterizedTypeReference<List<MyObject>>() {};
ResponseEntity<List<MyObject>> responseEntity = restTemplate.exchange(request, responseType);
MyObject obj = responseEntity.getBody();
}
Now I want to replace my above method to use WebClient
but I am new to WebClient
and not sure where to start. Any direction and help is appreciated.