Class ArmeriaRetrofitBuilder
- java.lang.Object
-
- com.linecorp.armeria.client.retrofit2.ArmeriaRetrofitBuilder
-
public final class ArmeriaRetrofitBuilder extends Object
A helper class for creating a newRetrofit
instance withArmeriaCallFactory
. For example,Retrofit retrofit = new ArmeriaRetrofitBuilder() .baseUrl("http://localhost:8080/") .build(); MyApi api = retrofit.create(MyApi.class); Response<User> user = api.getUser().execute();
ArmeriaRetrofitBuilder
even supportsEndpointGroup
, so you can createRetrofit
like below,EndpointGroupRegistry.register("foo", new StaticEndpointGroup(Endpoint.of("127.0.0.1", 8080)), ROUND_ROBIN); Retrofit retrofit = new ArmeriaRetrofitBuilder() .baseUrl("http://group:foo/") .build();
-
-
Constructor Summary
Constructors Constructor Description ArmeriaRetrofitBuilder()
Creates aArmeriaRetrofitBuilder
with the defaultClientFactory
.ArmeriaRetrofitBuilder(com.linecorp.armeria.client.ClientFactory clientFactory)
Creates aArmeriaRetrofitBuilder
with the specifiedClientFactory
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ArmeriaRetrofitBuilder
addCallAdapterFactory(CallAdapter.Factory factory)
Adds the specified call adapter factory for supporting service method return types other thanCall
.ArmeriaRetrofitBuilder
addConverterFactory(Converter.Factory factory)
Adds the specified converter factory for serialization and deserialization of objects.ArmeriaRetrofitBuilder
baseUrl(String baseUrl)
Sets the API base URL.Retrofit
build()
Returns a newly-createdRetrofit
based on the properties of this builder.ArmeriaRetrofitBuilder
callbackExecutor(Executor executor)
ArmeriaRetrofitBuilder
streaming(boolean streaming)
Sets the streaming flag to make Armeria client fully supportStreaming
.ArmeriaRetrofitBuilder
validateEagerly(boolean validateEagerly)
When callingRetrofit.create(java.lang.Class<T>)
on the resultingRetrofit
instance, eagerly validate the configuration of all methods in the supplied interface.ArmeriaRetrofitBuilder
withClientOptions(BiFunction<String,? super com.linecorp.armeria.client.ClientOptionsBuilder,com.linecorp.armeria.client.ClientOptionsBuilder> configurator)
Sets theBiFunction
that is applied to the underlyingHttpClient
.
-
-
-
Constructor Detail
-
ArmeriaRetrofitBuilder
public ArmeriaRetrofitBuilder()
Creates aArmeriaRetrofitBuilder
with the defaultClientFactory
.
-
ArmeriaRetrofitBuilder
public ArmeriaRetrofitBuilder(com.linecorp.armeria.client.ClientFactory clientFactory)
Creates aArmeriaRetrofitBuilder
with the specifiedClientFactory
.
-
-
Method Detail
-
baseUrl
public ArmeriaRetrofitBuilder baseUrl(String baseUrl)
Sets the API base URL.- See Also:
Retrofit.Builder.baseUrl(String)
-
withClientOptions
public ArmeriaRetrofitBuilder withClientOptions(BiFunction<String,? super com.linecorp.armeria.client.ClientOptionsBuilder,com.linecorp.armeria.client.ClientOptionsBuilder> configurator)
Sets theBiFunction
that is applied to the underlyingHttpClient
.- Parameters:
configurator
- aBiFunction
whose first argument is the the URI of the server endpoint and whose second argument is theClientOptionsBuilder
with default options of the new derived client
-
addConverterFactory
public ArmeriaRetrofitBuilder addConverterFactory(Converter.Factory factory)
Adds the specified converter factory for serialization and deserialization of objects.
-
addCallAdapterFactory
public ArmeriaRetrofitBuilder addCallAdapterFactory(CallAdapter.Factory factory)
Adds the specified call adapter factory for supporting service method return types other thanCall
.
-
callbackExecutor
public ArmeriaRetrofitBuilder callbackExecutor(Executor executor)
Sets theExecutor
on whichCallback
methods are invoked when returningCall
from your service method.Note:
executor
is not used forcustom method return types
.
-
streaming
public ArmeriaRetrofitBuilder streaming(boolean streaming)
Sets the streaming flag to make Armeria client fully supportStreaming
. If this flag isfalse
, Armeria client will buffer all data and call a callback after receiving the data completely, even if a service method was annotated withStreaming
. By enabling this flag, Armeria client will use theExecutor
specified withcallbackExecutor(Executor)
to read the data in a blocking way.Note: It is not recommended to have the service methods both with and without the
Streaming
annotation in the same interface. Consider separating them into different interfaces and using different builder to build the service.- See Also:
Streaming
-
validateEagerly
public ArmeriaRetrofitBuilder validateEagerly(boolean validateEagerly)
When callingRetrofit.create(java.lang.Class<T>)
on the resultingRetrofit
instance, eagerly validate the configuration of all methods in the supplied interface.
-
-