How to consume a Reactive Spring Rest API with WebClient

Viewed 9071

I need to consume a reactive rest API (built with spring webflux) on a backend job (executable jar).

I've read about Spring WebClient, but I am not understanding some points.

For instance:

WebClient webClient = WebClient.create("http://localhost:8080");

Mono<Person> person = webClient.get()
        .uri("/persons/{id}", 42)
        .accept(MediaType.APPLICATION_JSON)
        .exchange()
        .then(response -> response.bodyToMono(Person.class));

On the last line, there is a "bodyToMono". So that's my question:

If the Rest API being called is already a reactive service, do I need to transform the response to a mono? Is there some point I'm missing?

From my perspective, I think could have a way to let explicit in the code that my Rest API is reactive, but probably is something I am not aware about.

1 Answers
Related