Home » Java » SpringBoot: How to call a API chain using reactive programming?

SpringBoot: How to call a API chain using reactive programming?

Posted by: admin July 15, 2018 Leave a comment

Questions:

I want to call a Mono in middle of another Flux streams sending a parameter of Flux to mono.
I’m using WebClient from SpringBoot.

I tried this:

WebClient client = WebClient.create();
    client.get().uri("http://localhost:8081/api/{param1}", param1)
        .retrieve()
        .bodyToFlux(String.class)
        .zipWith(
            client.get().uri("http://localhost:8082/api/{param2}", param2)
            .retrieve()
            .bodyToMono(String.class);
        )
        .map(tuple -> {
          return tuple.getT1() + tuple.getT2();
        })

But how can I send to param2 the return of first API call? And get both response after?
The first API return many values and for each value I need to call the second API.

Thanks

Answers: