Request - SwiftDocOrg/Alamofire GitHub Wiki
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.Persistencefor the createdURLCredential..forSessionby 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
DispatchQueueto execute the closure on..mainby 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
DispatchQueueto execute the closure on..mainby 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.