Created
August 25, 2023 16:21
-
-
Save tomatophobia/3a5774fff9f84ac56e8b5fa9668b9256 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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