retrofit / retrofit2

Package retrofit2

Types

Call

interface Call<T : Any!> : Cloneable

An invocation of a Retrofit method that sends a request to a webserver and returns a response. Each call yields its own HTTP request and response pair. Use #clone to make multiple calls with the same parameters to the same webserver; this may be used to implement polling or to retry a failed call.

CallAdapter

interface CallAdapter<R : Any!, T : Any!>

Adapts a Call with response type R into the type of T. Instances are created by a factory which is into the Retrofit instance.

Callback

interface Callback<T : Any!>

Communicates responses from a server or offline requests. One and only one method will be invoked in response to a given request.

Converter

interface Converter<F : Any!, T : Any!>

Convert objects to and from their representation in HTTP. Instances are created by which is installed into the Retrofit instance.

Invocation

class Invocation

A single invocation of a Retrofit service interface method. This class captures both the method that was called and the arguments to the method.

Response

class Response<T : Any!>

An HTTP response.

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.

Annotations

SkipCallbackExecutor

class SkipCallbackExecutor

Change the behavior of a Call<BodyType> return type to not use the for invoking the onResponse or onFailure methods.


  @SkipCallbackExecutor
  @GET("user/{id}/token")
  Call<String> getToken(@Path("id") long id);
  
This annotation can also be used when a CallAdapter.Factory explicitly delegates to the built-in factory for Call via Retrofit#nextCallAdapter(CallAdapter.Factory, * Type, Annotation[]) in order for the returned Call to skip the executor. (Note: by default, a Call supplied directly to a CallAdapter will already skip the callback executor. The annotation is only useful when looking up the built-in adapter.)

Exceptions

HttpException

open class HttpException : RuntimeException

Exception for an unexpected, non-2xx HTTP response.

Functions

await

suspend fun <T : Any> Call<T>.await(): T

awaitResponse

suspend fun <T> Call<T>.awaitResponse(): Response<T>

create

fun <T> Retrofit.create(): T