WeatherWebApi { public static CompletableFuture<List<WeatherInfo>> pastWeather(double lat, double log, LocalDate from, LocalDate to) throws IOException { String path = HOST + String.format(PATH_PAST_WEATHER, lat, log, from, to, WEATHER_KEY); AsyncHttpClient ahc = Dsl.asyncHttpClient(); return ahc .prepareGet(path) .execute() .toCompletableFuture() .thenApply(Response::getResponseBody) .whenComplete((body, err) -> close(ahc)) .thenApply(body -> { PastWeatherDto dto = gson.fromJson(body, PastWeatherDto.class); return fromDtoToWeatherInfo(dto); }); }  static CompletableFuture<List<WeatherInfo>> pastWeather(double lat, double log, LocalDate from, LocalDate to);  }
@Test public void testPastWeatherAsync() throws IOException { CompletableFuture<List<WeatherInfo>> cf = WeatherWebApi .pastWeather(37.017, -7.933, parse("2019-04-01"), parse("2019-04-30")); cf .thenAccept(wis -> wis.stream().findFirst().ifPresent(out::println)) .join(); cf .thenApply(wis -> wis.stream().mapToInt(WeatherInfo::getTempC).max()) .thenAccept(temp -> temp.ifPresent(out::println)) .join(); }