0

I make a request with webClient in spring boot here is the request above:

Mono<ClientResponse> clientResponse = webClientBuilder
                .build()
                .post()
                .uri(societe.get(0)
                        .getApi_login())
                .contentType(MediaType.APPLICATION_JSON)
                .bodyValue(
                        identify)
                .exchange();

my question is how can i wait the result of the request before executing another instruction

Veron
  • 3
  • 2
  • 6
  • Are the other instructions dependent on the result? If not, I think that you can just proceed as normal. And If they are dependent, you can use operations such as doOnSuccess or zip it with another etc. Without knowing your use-case, it is hard to give any advice. – thinkgruen May 26 '22 at 14:44
  • thank you @thinkgruen for the answer. Yes they are the other instructions dependent on the result and the problem these instructions runs before the result and i get errors – Veron May 26 '22 at 15:22
  • could you add a bit more code so that we can see how the calls are chained? – thinkgruen May 26 '22 at 19:18

1 Answers1

0

How to use WebClient to execute synchronous request?

Add .block()

Something similar like this, I don't use flux too much, also can't test it:

Mono<ClientResponse> clientResponse = webClientBuilder
                .build()
                .post()
                .uri(societe.get(0)
                        .getApi_login())
                .contentType(MediaType.APPLICATION_JSON)
                .bodyValue(
                        identify)
                .exchange()
                .block();
stacktrace2234
  • 1,172
  • 1
  • 12
  • 22
  • First rule of Webflux: If you cannot write non-blocking code - don't use Webflux. This solution makes no sense and if you follow the comments below the (bad) answer you linked, you will eventually end up [here](https://stackoverflow.com/a/51456050/3393379) – thinkgruen May 26 '22 at 19:27
  • Yet, but he asked how to do it. The answer is correct, even if it is not suggested. – stacktrace2234 May 30 '22 at 05:18