-1

When using WebClient just to replace RestTemplate, i.e. every call is synchronous, do I have still to choose between a Flux or Mono response or does it not matter anymore because it is synchronous anyway?

As an example:

Mono<List<Customer>> response = this.apiClient.getWebClient()
 .put()
 .uri(URI.create("http://localhost:8080/api/v1/"))
 .body(BodyInserters.fromValue(StammdatenBaseError.builder().build()))
 .retrieve()
 .bodyToMono(new ParameterizedTypeReference<Customer>() {});

List<Customer> customers = response.block(); // .block() induces the call to be a synchronous one.

Makes it a difference if the return type is Flux<List<Customer>> or not?

The thing is that here it is explained to use Flux for Collections and Mono for single values but I don't know if this applies also for the good old sync approach?

kladderradatsch
  • 596
  • 5
  • 18
  • Your question lacks clarity. Please better describe your situation. webClient will return response body either as a Mono or a Flux, depending on the method used (bodyToMono vs bodyToFlux). What do you need to make synchronous ? Do you need to chain calls ? Or consume response bodies from a non-reactive third-party code ? – amanin Aug 22 '23 at 06:53

0 Answers0