This module provides to use Spring's WebClient as reactive, non-blocking HTTP implementation.
<dependency>
<groupId>com.github.ljtfreitas.julian-http-client</groupId>
<artifactId>julian-http-client-http-spring-web-flux</artifactId>
<version>${julian-http-client-version}</version>
</dependency>
dependencies {
implementation("com.github.ljtfreitas.julian-http-client:julian-http-client-http-spring-web-flux:$julianHttpClientVersion")
}
We just need to configure the ProxyBuilder
to use the implementation provided for this module:
import com.github.ljtfreitas.julian.http.spring.webflux.WebClientHTTP;
interface MyApi {}
WebClientHTTP webClientHttp = new WebClientHTTP();
MyApi myApi = new ProxyBuilder()
.http()
.with(webClientHttp)
.build(SimpleApi.class, "http://my.api.com");
WebClientHTTP
uses a default WebClient
, but we can customize it:
import com.github.ljtfreitas.julian.http.spring.webflux.WebClientHTTP;
import org.springframework.web.reactive.function.client.WebClient;
interface MyApi {}
WebClient webClient = WebClient.builder()
//WebClient customizations...
.build();
WebClientHTTP webClientHttp = new WebClientHTTP(webClient);
MyApi myApi = new ProxyBuilder()
.http()
.client()
.with(webClientHttp)
.and()
.build(SimpleApi.class, "http://my.api.com");
WebClient
has built-in support for interceptors, media types and error handling. So, all these concerns are delegated for it; in other words, julian-http-client
doesn't apply default serialization/deserialization behaviors and interceptors-chain when using WebClientHTTP
. All these stuff are done by WebClient
.
In case of failures (IO errors or 4xx/5xx responses), WebClient
exceptions wiil be translated to julian-http-client
ones, so the error handling on the client side can keep the same.