Browse Source

Added instructions about AsyncClient

pull/1184/head
Marvin Froeder 5 years ago committed by GitHub
parent
commit
40c026ea7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      README.md

31
README.md

@ -939,3 +939,34 @@ interface GitHub { @@ -939,3 +939,34 @@ interface GitHub {
}
}
```
### Async execution via `CompletableFuture`
Feign 10.8 introduces a new builder `AsyncFeign` that allow methods to return `CompletableFuture` instances.
```java
interface GitHub {
@RequestLine("GET /repos/{owner}/{repo}/contributors")
CompletableFuture<List<Contributor>> contributors(@Param("owner") String owner, @Param("repo") String repo);
}
public class MyApp {
public static void main(String... args) {
GitHub github = AsyncFeign.asyncBuilder()
.decoder(new GsonDecoder())
.target(GitHub.class, "https://api.github.com");
// Fetch and print a list of the contributors to this library.
CompletableFuture<List<Contributor>> contributors = github.contributors("OpenFeign", "feign");
for (Contributor contributor : contributors.get(1, TimeUnit.SECONDS)) {
System.out.println(contributor.login + " (" + contributor.contributions + ")");
}
}
}
```
Initial implementation include 2 async clients:
- `AsyncClient.Default`
- `AsyncApacheHttp5Client`

Loading…
Cancel
Save