Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Request

mattt edited this page Sep 18, 2020 · 4 revisions

Request

Request is the common superclass of all Alamofire request types and provides common state, delegate, and callback handling.

public class Request

Inheritance

CustomStringConvertible, Equatable, Hashable

Nested Type Aliases

ProgressHandler

Closure type executed when monitoring the upload or download progress of a request.

public typealias ProgressHandler = (Progress) -> Void

ValidationResult

Used to represent whether a validation succeeded or failed.

public typealias ValidationResult = Result<Void, Error>

Properties

didResumeNotification

Posted when a Request is resumed. The Notification contains the resumed Request.

let didResumeNotification

didSuspendNotification

Posted when a Request is suspended. The Notification contains the suspended Request.

let didSuspendNotification

didCancelNotification

Posted when a Request is cancelled. The Notification contains the cancelled Request.

let didCancelNotification

didFinishNotification

Posted when a Request is finished. The Notification contains the completed Request.

let didFinishNotification

didResumeTaskNotification

Posted when a URLSessionTask is resumed. The Notification contains the Request associated with the URLSessionTask.

let didResumeTaskNotification

didSuspendTaskNotification

Posted when a URLSessionTask is suspended. The Notification contains the Request associated with the URLSessionTask.

let didSuspendTaskNotification

didCancelTaskNotification

Posted when a URLSessionTask is cancelled. The Notification contains the Request associated with the URLSessionTask.

let didCancelTaskNotification

didCompleteTaskNotification

Posted when a URLSessionTask is completed. The Notification contains the Request associated with the URLSessionTask.

let didCompleteTaskNotification

id

UUID providing a unique identifier for the Request, used in the Hashable and Equatable conformances.

let id:​ UUID

underlyingQueue

The serial queue for all internal async actions.

let underlyingQueue:​ DispatchQueue

serializationQueue

The queue used for all serialization actions. By default it's a serial queue that targets underlyingQueue.

let serializationQueue:​ DispatchQueue

eventMonitor

EventMonitor used for event callbacks.

let eventMonitor:​ EventMonitor?

interceptor

The Request's interceptor.

let interceptor:​ RequestInterceptor?

delegate

The Request's delegate.

var delegate:​ RequestDelegate?

state

State of the Request.

var state:​ State

isInitialized

Returns whether state is .initialized.

var isInitialized:​ Bool

isResumed

Returns whether state is .resumed`.

var isResumed:​ Bool

isSuspended

Returns whether state is .suspended.

var isSuspended:​ Bool

isCancelled

Returns whether state is .cancelled.

var isCancelled:​ Bool

isFinished

Returns whether state is .finished.

var isFinished:​ Bool

uploadProgress

Progress of the upload of the body of the executed URLRequest. Reset to 0 if the Request is retried.

let uploadProgress

downloadProgress

Progress of the download of any response data. Reset to 0 if the Request is retried.

let downloadProgress

redirectHandler

RedirectHandler set on the instance.

var redirectHandler:​ RedirectHandler?

cachedResponseHandler

CachedResponseHandler set on the instance.

var cachedResponseHandler:​ CachedResponseHandler?

credential

URLCredential used for authentication challenges. Created by calling one of the authenticate methods.

var credential:​ URLCredential?

requests

All URLRequests created on behalf of the Request, including original and adapted requests.

var requests:[URLRequest]

firstRequest

First URLRequest created on behalf of the Request. May not be the first one actually executed.

var firstRequest:​ URLRequest?

lastRequest

Last URLRequest created on behalf of the Request.

var lastRequest:​ URLRequest?

request

Current URLRequest created on behalf of the Request.

var request:​ URLRequest?

performedRequests

URLRequests from all of the URLSessionTasks executed on behalf of the Request. May be different from requests due to URLSession manipulation.

var performedRequests:[URLRequest]

response

HTTPURLResponse received from the server, if any. If the Request was retried, this is the response of the last URLSessionTask.

var response:​ HTTPURLResponse?

tasks

All URLSessionTasks created on behalf of the Request.

var tasks:[URLSessionTask]

firstTask

First URLSessionTask created on behalf of the Request.

var firstTask:​ URLSessionTask?

lastTask

Last URLSessionTask crated on behalf of the Request.

var lastTask:​ URLSessionTask?

task

Current URLSessionTask created on behalf of the Request.

var task:​ URLSessionTask?

allMetrics

All URLSessionTaskMetrics gathered on behalf of the Request. Should correspond to the tasks created.

var allMetrics:[URLSessionTaskMetrics]

firstMetrics

First URLSessionTaskMetrics gathered on behalf of the Request.

var firstMetrics:​ URLSessionTaskMetrics?

lastMetrics

Last URLSessionTaskMetrics gathered on behalf of the Request.

var lastMetrics:​ URLSessionTaskMetrics?

metrics

Current URLSessionTaskMetrics gathered on behalf of the Request.

var metrics:​ URLSessionTaskMetrics?

retryCount

Number of times the Request has been retried.

var retryCount:​ Int

error

Error returned from Alamofire internally, from the network request directly, or any validators executed.

var error:​ AFError?

description

A textual representation of this instance, including the HTTPMethod and URL if the URLRequest has been created, as well as the response status code, if a response has been received.

var description:​ String

Methods

cancel()

Cancels the instance. Once cancelled, a Request can no longer be resumed or suspended.

@discardableResult public func cancel() -> Self

Returns

The instance.

suspend()

Suspends the instance.

@discardableResult public func suspend() -> Self

Returns

The instance.

resume()

Resumes the instance.

@discardableResult public func resume() -> Self

Returns

The instance.

authenticate(username:​password:​persistence:​)

Associates a credential using the provided values with the instance.

@discardableResult public func authenticate(username:​ String, password:​ String, persistence:​ URLCredential.Persistence = .forSession) -> Self

Parameters

  • username:​ The username.
  • password:​ The password.
  • persistence:​ The URLCredential.Persistence for the created URLCredential. .forSession by default.

Returns

The instance.

authenticate(with:​)

Associates the provided credential with the instance.

@discardableResult public func authenticate(with credential:​ URLCredential) -> Self

Parameters

  • credential:​ The URLCredential.

Returns

The instance.

downloadProgress(queue:​closure:​)

Sets a closure to be called periodically during the lifecycle of the instance as data is read from the server.

@discardableResult public func downloadProgress(queue:​ DispatchQueue = .main, closure:@escaping ProgressHandler) -> Self

Parameters

  • queue:​ The DispatchQueue to execute the closure on. .main by default.
  • closure:​ The closure to be executed periodically as data is read from the server.

Returns

The instance.

uploadProgress(queue:​closure:​)

Sets a closure to be called periodically during the lifecycle of the instance as data is sent to the server.

@discardableResult public func uploadProgress(queue:​ DispatchQueue = .main, closure:@escaping ProgressHandler) -> Self

Parameters

  • queue:​ The DispatchQueue to execute the closure on. .main by default.
  • closure:​ The closure to be executed periodically as data is sent to the server.

Returns

The instance.

redirect(using:​)

Sets the redirect handler for the instance which will be used if a redirect response is encountered.

@discardableResult public func redirect(using handler:​ RedirectHandler) -> Self

Parameters

  • handler:​ The RedirectHandler.

Returns

The instance.

cacheResponse(using:​)

Sets the cached response handler for the Request which will be used when attempting to cache a response.

@discardableResult public func cacheResponse(using handler:​ CachedResponseHandler) -> Self

Parameters

  • handler:​ The CachedResponseHandler.

Returns

The instance.

cURLDescription(calling:​)

Sets a handler to be called when the cURL description of the request is available.

@discardableResult public func cURLDescription(calling handler:@escaping (String) -> Void) -> Self

Parameters

  • handler:​ Closure to be called when the cURL description is available.

Returns

The instance.

==(lhs:​rhs:​)

public static func ==(lhs:​ Request, rhs:​ Request) -> Bool

hash(into:​)

public func hash(into hasher:inout Hasher)

cURLDescription()

cURL representation of the instance.

public func cURLDescription() -> String

Returns

The cURL equivalent of the instance.

Types
Protocols
Global Typealiases
Clone this wiki locally