Skip to content

Instantly share code, notes, and snippets.

@tomatophobia
Last active August 26, 2023 11:47
Show Gist options
  • Save tomatophobia/0a48a62b464a6a576d1228eab7b7febf to your computer and use it in GitHub Desktop.
Save tomatophobia/0a48a62b464a6a576d1228eab7b7febf to your computer and use it in GitHub Desktop.
@Get("/test")
public HttpResponse getTest(RequestContext ctx) {
CompletableFuture<HttpResponse> future = new CompletableFuture<>();
WebClient client = WebClient.of("https://icanhazdadjoke.com");
HttpResponse response = client.execute(RequestHeaders.of(HttpMethod.GET, "/", HttpHeaderNames.ACCEPT, HttpHeaderValues.APPLICATION_JSON));
ContextAwareEventLoop eventLoop = ctx.eventLoop();
response.aggregate().thenAcceptAsync(aggregatedRes -> {
AggregatedHttpResponse res = ... // do something with `aggregatedRes`
future.complete(res.toHttpResponse());
}, eventLoop);
return HttpResponse.from(future);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment