Last active
August 26, 2023 11:47
-
-
Save tomatophobia/0a48a62b464a6a576d1228eab7b7febf 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)); | |
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