This library helps you to easily create other libraries interacting with services using asynchronous requests and returning CompletableFuture. The serialization and deserialization of domain objects are performed using Jackson.
Presently, it supports the following HTTP clients:
- Java HTTP client (included since Java 11)
- Apache HTTP client 5.4
- OkHttp client 4.12
- Vert.x client 4.5
The dependency is available in maven central (see badge for version):
<dependency>
<groupId>com.chavaillaz</groupId>
<artifactId>common-client</artifactId>
</dependency>
- Create the interfaces corresponding to every API you want to interact with (e.g.
UserApi
)- Make them extend Client to have methods to set proxy and authentication information
- Always return completable futures, either
CompletableFuture<YourDomainType>
orCompletableFuture<Void>
- Create the authentication method for your service (in case it does not already exist) by extending
Authentication
- Presently, there are token and password authentications available
- Create an implementation of your interfaces by extending the available abstract classes for each HTTP client
- For Apache HTTP: AbstractApacheHttpClient
- For Java HTTP: AbstractJavaHttpClient
- For OkHttp: AbstractOkHttpClient
- For Vert.x: AbstractVertxHttpClient
- Create a central client to manage and get other ones by extending
AbstractClient
- Use LazyCachedObject to simplify the cache management of your clients
If you have a feature request or found a bug, you can:
- Write an issue
- Create a pull request
The code style is based on the default one from IntelliJ, except for the following cases:
Imports are ordered as follows:
- All static imports in a block
- Java non-static imports in a block
- All non-static imports in a block
A single blank line separates every block. Within each block the imported names appear in alphabetical sort order. Wildcard imports, static or otherwise, are not used.
This project is under Apache 2.0 License.