Skip to content

Instantly share code, notes, and snippets.

@tomatophobia
Created August 25, 2023 16:21
Show Gist options
  • Save tomatophobia/3a5774fff9f84ac56e8b5fa9668b9256 to your computer and use it in GitHub Desktop.
Save tomatophobia/3a5774fff9f84ac56e8b5fa9668b9256 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));
response.aggregate().thenAccept(aggregatedRes -> {
try (SafeCloseable ignored = ctx.push()) {
AggregatedHttpResponse res = ... // do something with `aggregatedRes`
future.complete(res.toHttpResponse());
}
});
return HttpResponse.from(future);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment