This project demonstrates how JAX-RS client can be wrapped to provide transparent handling of retries when invoking HTTP requests. Handling retries transparently in the wrapper relieves the calling code from having to implement complex retry logic.
The class HttpApiClient wraps javax.ws.rs.client.Client
and adds automatic retries on top of its functions. While it uses a JAX-RS Client internally, it can be used not only for REST API calls but also for other types of HTTP APIs like SOAP APIs.
The wrapper performs retries transparently using one of the following retry configurations:
- The wrapper's default retry config (which can be modified by the caller when instantiating the wrapper)
- The specified retry config for each HTTP operation
The wrapper uses Resilience4j for retries.
The HttpApiClientTests class demos the usage of the wrapper. The tests use WireMock for running a REST API server that provides stubbed responses. Each test then uses the wrapper to demonstrate a unit of functionality.
- Configuring URL and query parameters
- Automatic API pagination
- HTTP POST-based requests
- Setting additional request headers and client properties
- Support for asynchronous API requests