I don't really know how to translate the following call to the spring webflux webclient correctly.
userIds is the List and I was able to call the service using the following syntax but I could not get that working with the Spring WebFlux WebClient. Please help me if there is any of you know how to do it.
String url = "http://profile.service.com/v1/profiles/bulk";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
ResponseEntity<List<MiniProfile>> responseEntity;
try {
responseEntity = restTemplate.exchange(url, HttpMethod.POST, new
HttpEntity(userIds, headers), new
ParameterizedTypeReference<List<MiniProfile>>() {});
} catch (RestClientException e) {
responseEntity = new ResponseEntity<List<MiniProfile>>(HttpStatus.OK);
}
return responseEntity.getBody();
This is the way I got it translate to the Webflux WebClient:
Flux<String> flux = Flux.fromIterable(userIds);
return readWebClient.post().uri("/v1/profiles/bulk")
.body(BodyInserters.fromPublisher(flux, String.class))
.retrieve().bodyToFlux(MiniProfile.class);