retrofit / retrofit2 / Retrofit

Retrofit

class Retrofit

Retrofit adapts a Java interface to HTTP calls by using annotations on the declared methods to define how requests are made. Create instances using the builder and pass your interface to #create to generate an implementation.

For example,


  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl("https://api.example.com/")
      .addConverterFactory(GsonConverterFactory.create())
      .build();
 
  MyApi api = retrofit.create(MyApi.class);
  Response<User> user = api.getUser().execute();
  

Author
Bob Lee (bob@squareup.com)

Author
Jake Wharton (jw@squareup.com)

Types

Builder

class Builder

Build a new Retrofit.

Functions

baseUrl

fun baseUrl(): HttpUrl!

The API base URL.

callAdapter

fun callAdapter(returnType: Type!, annotations: Array<Annotation!>!): CallAdapter<*, *>!

Returns the CallAdapter for returnType from the available .

callAdapterFactories

fun callAdapterFactories(): MutableList<CallAdapter.Factory!>!

Returns a list of the factories tried when creating a #callAdapter(Type, * Annotation[]) call adapter}.

callbackExecutor

fun callbackExecutor(): Executor?

The executor used for Callback methods on a Call. This may be null, in which case callbacks should be made synchronously on the background thread.

callFactory

fun callFactory(): Factory!

The factory used to create OkHttp calls for sending a HTTP requests. Typically an instance of OkHttpClient.

converterFactories

fun converterFactories(): MutableList<Converter.Factory!>!

Returns an unmodifiable list of the factories tried when creating a , a , or a .

create

fun <T : Any!> create(service: Class<T>!): T

Create an implementation of the API endpoints defined by the service interface.

newBuilder

fun newBuilder(): Retrofit.Builder!

nextCallAdapter

fun nextCallAdapter(skipPast: CallAdapter.Factory?, returnType: Type!, annotations: Array<Annotation!>!): CallAdapter<*, *>!

Returns the CallAdapter for returnType from the available except skipPast.

nextRequestBodyConverter

fun <T : Any!> nextRequestBodyConverter(skipPast: Converter.Factory?, type: Type!, parameterAnnotations: Array<Annotation!>!, methodAnnotations: Array<Annotation!>!): Converter<T, RequestBody!>!

Returns a Converter for type to RequestBody from the available factories except skipPast.

nextResponseBodyConverter

fun <T : Any!> nextResponseBodyConverter(skipPast: Converter.Factory?, type: Type!, annotations: Array<Annotation!>!): Converter<ResponseBody!, T>!

Returns a Converter for ResponseBody to type from the available factories except skipPast.

requestBodyConverter

fun <T : Any!> requestBodyConverter(type: Type!, parameterAnnotations: Array<Annotation!>!, methodAnnotations: Array<Annotation!>!): Converter<T, RequestBody!>!

Returns a Converter for type to RequestBody from the available factories.

responseBodyConverter

fun <T : Any!> responseBodyConverter(type: Type!, annotations: Array<Annotation!>!): Converter<ResponseBody!, T>!

Returns a Converter for ResponseBody to type from the available factories.

stringConverter

fun <T : Any!> stringConverter(type: Type!, annotations: Array<Annotation!>!): Converter<T, String!>!

Returns a Converter for type to String from the available .

Extension Functions

create

fun <T> Retrofit.create(): T