Skip to content

Commit 24704fb

Browse files
committed
Improve javadoc for HttpAsyncResponse
1 parent a959dbc commit 24704fb

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

client/src/main/java/io/avaje/http/client/HttpAsyncResponse.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,53 @@ public interface HttpAsyncResponse {
1010

1111
/**
1212
* Process discarding response body as {@literal HttpResponse<Void>}.
13+
*
14+
* <pre>{@code
15+
*
16+
* clientContext.request()
17+
* .path("hello/world")
18+
* .GET()
19+
* .async().asDiscarding()
20+
* .whenComplete((hres, throwable) -> {
21+
*
22+
* if (throwable != null) {
23+
* ...
24+
* } else {
25+
* int statusCode = hres.statusCode();
26+
* ...
27+
* }
28+
* });
29+
*
30+
* }</pre>
1331
*/
1432
CompletableFuture<HttpResponse<Void>> asDiscarding();
1533

1634
/**
1735
* Process as String response body {@literal HttpResponse<String>}.
36+
*
37+
* <pre>{@code
38+
*
39+
* clientContext.request()
40+
* .path("hello/world")
41+
* .GET()
42+
* .async().asString()
43+
* .whenComplete((hres, throwable) -> {
44+
*
45+
* if (throwable != null) {
46+
* ...
47+
* } else {
48+
* int statusCode = hres.statusCode();
49+
* String body = hres.body();
50+
* ...
51+
* }
52+
* });
53+
*
54+
* }</pre>
1855
*/
1956
CompletableFuture<HttpResponse<String>> asString();
2057

2158
/**
22-
* Process expecting a (json) bean response body.
59+
* Process expecting a bean response body (typically from json content).
2360
* <p>
2461
* If the HTTP statusCode is 300 or above a HttpException is throw which
2562
* contains the HttpResponse.

client/src/test/java/io/avaje/http/client/HelloControllerTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ void get_helloMessage() {
5252
@Test
5353
void async_get_asString() throws ExecutionException, InterruptedException {
5454

55+
AtomicReference<HttpResponse<String>> ref = new AtomicReference<>();
56+
5557
final CompletableFuture<HttpResponse<String>> future = clientContext.request()
5658
.path("hello").path("message")
5759
.GET()
58-
.async().asString();
60+
.async().asString()
61+
.whenComplete((hres, throwable) -> {
62+
ref.set(hres);
63+
assertThat(hres.statusCode()).isEqualTo(200);
64+
assertThat(hres.body()).contains("hello world");
65+
});
5966

6067
final HttpResponse<String> hres = future.get();
68+
assertThat(hres).isSameAs(ref.get());
6169
assertThat(hres.body()).contains("hello world");
6270
assertThat(hres.statusCode()).isEqualTo(200);
6371
}

0 commit comments

Comments
 (0)