public static final class Retrofit.Builder
extends java.lang.Object
| Constructor and Description |
|---|
Builder() |
| Modifier and Type | Method and Description |
|---|---|
Retrofit.Builder |
addCallAdapterFactory(CallAdapter.Factory factory)
Add a call adapter factory for supporting service method return types other than
Call. |
Retrofit.Builder |
addConverterFactory(Converter.Factory factory)
Add converter factory for serialization and deserialization of objects.
|
Retrofit.Builder |
baseUrl(okhttp3.HttpUrl baseUrl)
Set the API base URL.
|
Retrofit.Builder |
baseUrl(java.lang.String baseUrl)
Set the API base URL.
|
Retrofit.Builder |
baseUrl(java.net.URL baseUrl)
Set the API base URL.
|
Retrofit |
build()
Create the
Retrofit instance using the configured values. |
java.util.List<CallAdapter.Factory> |
callAdapterFactories()
Returns a modifiable list of call adapter factories.
|
Retrofit.Builder |
callbackExecutor(java.util.concurrent.Executor executor)
|
Retrofit.Builder |
callFactory(okhttp3.Call.Factory factory)
Specify a custom call factory for creating
Call instances. |
Retrofit.Builder |
client(okhttp3.OkHttpClient client)
The HTTP client used for requests.
|
java.util.List<Converter.Factory> |
converterFactories()
Returns a modifiable list of converter factories.
|
Retrofit.Builder |
validateEagerly(boolean validateEagerly)
When calling
Retrofit.create(java.lang.Class<T>) on the resulting Retrofit instance, eagerly validate the
configuration of all methods in the supplied interface. |
public Retrofit.Builder client(okhttp3.OkHttpClient client)
This is a convenience method for calling callFactory.
public Retrofit.Builder callFactory(okhttp3.Call.Factory factory)
Call instances.
Note: Calling client(okhttp3.OkHttpClient) automatically sets this value.
public Retrofit.Builder baseUrl(java.net.URL baseUrl)
baseUrl(HttpUrl)public Retrofit.Builder baseUrl(java.lang.String baseUrl)
baseUrl(HttpUrl)public Retrofit.Builder baseUrl(okhttp3.HttpUrl baseUrl)
The specified endpoint values (such as with @GET) are resolved against this
value using HttpUrl.resolve(String). The behavior of this matches that of an <a href=""> link on a website resolving on the current URL.
Base URLs should always end in /.
A trailing / ensures that endpoints values which are relative paths will correctly
append themselves to a base which has path components.
Correct:
Base URL: http://example.com/api/
Endpoint: foo/bar/
Result: http://example.com/api/foo/bar/
Incorrect:
Base URL: http://example.com/api
Endpoint: foo/bar/
Result: http://example.com/foo/bar/
This method enforces that baseUrl has a trailing /.
Endpoint values which contain a leading / are absolute.
Absolute values retain only the host from baseUrl and ignore any specified path
components.
Base URL: http://example.com/api/
Endpoint: /foo/bar/
Result: http://example.com/foo/bar/
Base URL: http://example.com/
Endpoint: /foo/bar/
Result: http://example.com/foo/bar/
Endpoint values may be a full URL.
Values which have a host replace the host of baseUrl and values also with a scheme
replace the scheme of baseUrl.
Base URL: http://example.com/
Endpoint: https://github.com/square/retrofit/
Result: https://github.com/square/retrofit/
Base URL: http://example.com
Endpoint: //github.com/square/retrofit/
Result: http://github.com/square/retrofit/ (note the scheme stays 'http')
public Retrofit.Builder addConverterFactory(Converter.Factory factory)
public Retrofit.Builder addCallAdapterFactory(CallAdapter.Factory factory)
Call.public Retrofit.Builder callbackExecutor(java.util.concurrent.Executor executor)
Callback methods are invoked when returning Call from
your service method.
Note: executor is not used for custom method
return types.
public java.util.List<CallAdapter.Factory> callAdapterFactories()
public java.util.List<Converter.Factory> converterFactories()
public Retrofit.Builder validateEagerly(boolean validateEagerly)
Retrofit.create(java.lang.Class<T>) on the resulting Retrofit instance, eagerly validate the
configuration of all methods in the supplied interface.public Retrofit build()
Retrofit instance using the configured values.
Note: If neither client(okhttp3.OkHttpClient) nor callFactory is called a default OkHttpClient will be created and used.