Using Spring boot Web client to request JSON from a REST API, the response body from the server is stored in a simple Map
. The request to the server contains an ID, but this isn't included in the response, but is required to interpret the response.
I would want to include the id in the result of the parallel call, so instead of instead of List<Map> data
should it be Map<UUID,Map> data
or similar. So the response from the server is paired with the id that was used to get the response.
List<Map> data = Flux.fromIterable(ids)
.parallel()
.runOn(Schedulers.elastic())
.flatMap(this::callAPI).sequential().collectList().block();
private Mono<Map> callAPI(UUID id) {
return client.get().uri(uriBuilder -> uriBuilder
.path("/{id}/")
.build(id))
.retrieve().bodyToMono(Map.class);
}