Reputation: 1
I'm trying to call an api with 2 call using webclient. The first call return a token. The second call use the token.
public Mono<GetToken> getToken{
return webClient
.get()
.uri(uriBuilder ->
uriBuilder
.path("api/getToken")
.build()
)
.retrieve()
.bodyToMono(Object.class);
}
public Mono<GetToken> getData{
return webClient
.get()
.uri(uriBuilder ->
uriBuilder
.path("api/getData/"+tokenID)
.build()
)
.retrieve()
.bodyToMono(Object2.class);
}
How can I use the data from the first request in the second without using the block() function
Upvotes: 0
Views: 562
Reputation: 89472
Use Mono#flatMap
.
Mono<Object2> res = getToken().flatMap(token -> getData(token));
Upvotes: 1