Skip to content

Commit d72a0ba

Browse files
committed
#21 Update README for HttpCall
1 parent 7932157 commit d72a0ba

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,29 @@ HttpResponse<String> hres = clientContext.request()
7777
.GET()
7878
.asString();
7979
```
80+
#### Example Async GET as String
81+
- All async requests use CompletableFuture&lt;T&gt;
82+
- throwable is a CompletionException
83+
- In the example below hres is of type HttpResponse&lt;String&gt;
8084

85+
```java
86+
clientContext.request()
87+
.path("hello")
88+
.GET()
89+
.async().asString() // CompletableFuture<HttpResponse<String>>
90+
.whenComplete((hres, throwable) -> {
91+
92+
if (throwable != null) {
93+
// CompletionException
94+
...
95+
} else {
96+
// HttpResponse<String>
97+
int statusCode = hres.statusCode();
98+
String body = hres.body();
99+
...
100+
}
101+
});
102+
```
81103

82104
## Overview of responses
83105

@@ -158,7 +180,7 @@ clientContext.request()
158180
// CompletionException
159181
...
160182
} else {
161-
// HttpResponse&lt;String&gt;
183+
// HttpResponse<String>
162184
int statusCode = hres.statusCode();
163185
String body = hres.body();
164186
...
@@ -381,6 +403,32 @@ CompletableFuture<HttpResponse<Void>> future = clientContext.request()
381403

382404
```
383405

406+
## HttpCall
407+
408+
If we are creating an API and want the client code to *choose* to execute
409+
the request asynchronously or synchronously then we can use `call()`.
410+
411+
The client can then choose to `execute()` the request synchronously or
412+
choose `async()` to execute the request asynchronously.
413+
414+
```java
415+
HttpCall<List<Customer>> call =
416+
clientContext.request()
417+
.path("customers")
418+
.GET()
419+
.call().list(Customer.class);
420+
421+
// Either execute synchronously
422+
List<Customer> customers = call.execute();
423+
424+
// Or execute asynchronously
425+
call.async()
426+
.whenComplete((customers, throwable) -> {
427+
...
428+
});
429+
```
430+
431+
384432
## BasicAuthIntercept - Authorization Basic / Basic Auth
385433

386434
We can use `BasicAuthIntercept` to intercept all requests adding a `Authorization: Basic ...`

0 commit comments

Comments
 (0)