This module provides to use OkHTTP as HTTP client implementation.
<dependency>
<groupId>com.github.ljtfreitas.julian-http-client</groupId>
<artifactId>julian-http-client-http-client-okhttp</artifactId>
<version>${julian-http-client-version}</version>
</dependency>
dependencies {
implementation("com.github.ljtfreitas.julian-http-client:julian-http-client-okhttp:$julianHttpClientVersion")
}
We need to configure the ProxyBuilder
to use the implementation provided for this module:
import com.github.ljtfreitas.julian.http.client.okhttp.OkHTTPClient;
interface MyApi {}
OkHTTPClient okHTTPClient = new OkHTTPClient();
MyApi myApi = new ProxyBuilder()
.http()
.client()
.with(okHTTPClient)
.and()
.build(MyApi.class, "http://my.api.com");
OkHTTPClient
creates a OkHttpClient instance using default options, but we can customize it:
import com.github.ljtfreitas.julian.http.client.okhttp.OkHTTPClient;
import okhttp3.OkHttpClient;
interface MyApi {}
OkHttpClient client = new OkHttpClient.Builder()
// ...
.build();
OkHTTPClient okHTTPClient = new OkHTTPClient(client);
MyApi myApi = new ProxyBuilder()
.http()
.client()
.with(okHTTPClient)
.and()
.build(MyApi.class, "http://my.api.com");