retrofit / retrofit2 / Call

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.

Calls may be executed synchronously with #execute, or asynchronously with . In either case the call can be canceled at any time with #cancel. A call that is busy writing its request or reading its response may receive a IOException; this is working as designed.

Functions

cancel

abstract fun cancel(): Unit

Cancel this call. An attempt will be made to cancel in-flight calls, and if the call has not yet been executed it never will be.

clone

abstract fun clone(): Call<T>

Create a new, identical call to this one which can be enqueued or executed even if this call has already been.

enqueue

abstract fun enqueue(callback: Callback<T>!): Unit

Asynchronously send the request and notify callback of its response or if an error occurred talking to the server, creating the request, or processing the response.

execute

abstract fun execute(): Response<T>!

Synchronously send the request and return its response.

isCanceled

abstract fun isCanceled(): Boolean

True if #cancel() was called.

isExecuted

abstract fun isExecuted(): Boolean

Returns true if this call has been either executed or . It is an error to execute or enqueue a call more than once.

request

abstract fun request(): Request!

The original HTTP request.

timeout

abstract fun timeout(): Timeout!

Returns a timeout that spans the entire call: resolving DNS, connecting, writing the request body, server processing, and reading the response body. If the call requires redirects or retries all must complete within one timeout period.

Extension Functions

await

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

awaitResponse

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