Request
open class Request
Request is the common superclass of all Alamofire request types and provides common state, delegate, and callback
handling.
-
State of the
Request, with managed transitions between states set when callingresume(),suspend(), orcancel()on theRequest.- initialized: Initial state of the
Request. - resumed: Set when
resume()is called. Any tasks created for theRequestwill haveresume()called on them in this state. - suspended: Set when
suspend()is called. Any tasks created for theRequestwill havesuspend()called on them in this state. - cancelled: Set when
cancel()is called. Any tasks created for theRequestwill havecancel()called on them. Unlikeresumedorsuspended, once in thecancelledstate, theRequestcan no longer transition to any other state.
Declaration
Swift
public enum State - initialized: Initial state of the
-
UUIDprividing a unique identifier for theRequest, used in theHashableandEquatableconformances.Declaration
Swift
public let id: UUID -
The serial queue for all internal async actions.
Declaration
Swift
public let underlyingQueue: DispatchQueue -
The queue used for all serialization actions. By default it’s a serial queue that targets
underlyingQueue.Declaration
Swift
public let serializationQueue: DispatchQueue -
EventMonitorused for event callbacks.Declaration
Swift
public let eventMonitor: EventMonitor? -
The
Request‘s interceptor.Declaration
Swift
public let interceptor: RequestInterceptor? -
The
Request‘s delegate.Declaration
Swift
public weak var delegate: RequestDelegate?
-
Returns whether
stateis.cancelled.Declaration
Swift
public var isCancelled: Bool { get } -
Returns whether
state is.resumed`.Declaration
Swift
public var isResumed: Bool { get } -
Returns whether
stateis.suspended.Declaration
Swift
public var isSuspended: Bool { get } -
Returns whether
stateis.initialized.Declaration
Swift
public var isInitialized: Bool { get } -
Closure type executed when monitoring the upload or download progress of a request.
Declaration
Swift
public typealias ProgressHandler = (Progress) -> Void -
Progressof the upload of the body of the executedURLRequest. Reset to0if theRequestis retried.Declaration
Swift
public let uploadProgress: Progress -
Progressof the download of any response data. Reset to0if theRequestis retried.Declaration
Swift
public let downloadProgress: Progress -
Undocumented
Declaration
Swift
public private(set) var redirectHandler: RedirectHandler? { get set } -
Undocumented
Declaration
Swift
public private(set) var cachedResponseHandler: CachedResponseHandler? { get set } -
URLCredentialused for authentication challenges. Created by calling one of theauthenticatemethods.Declaration
Swift
public private(set) var credential: URLCredential? { get set } -
All
URLRequestscreated on behalf of theRequest, including original and adapted requests.Declaration
Swift
public var requests: [URLRequest] { get } -
First
URLRequestcreated on behalf of theRequest. May not be the first one actually executed.Declaration
Swift
public var firstRequest: URLRequest? { get } -
Last
URLRequestcreated on behalf of theRequest.Declaration
Swift
public var lastRequest: URLRequest? { get } -
Current
URLRequestcreated on behalf of theRequest.Declaration
Swift
public var request: URLRequest? { get } -
URLRequests from all of theURLSessionTasks executed on behalf of theRequest.Declaration
Swift
public var performedRequests: [URLRequest] { get } -
HTTPURLResponsereceived from the server, if any. If theRequestwas retried, this is the response of the lastURLSessionTask.Declaration
Swift
public var response: HTTPURLResponse? { get } -
All
URLSessionTasks created on behalf of theRequest.Declaration
Swift
public var tasks: [URLSessionTask] { get } -
First
URLSessionTaskcreated on behalf of theRequest.Declaration
Swift
public var firstTask: URLSessionTask? { get } -
Last
URLSessionTaskcrated on behalf of theRequest.Declaration
Swift
public var lastTask: URLSessionTask? { get } -
Current
URLSessionTaskcreated on behalf of theRequest.Declaration
Swift
public var task: URLSessionTask? { get } -
All
URLSessionTaskMetricsgathered on behalf of theRequest. Should correspond to thetaskscreated.Declaration
Swift
public var allMetrics: [URLSessionTaskMetrics] { get } -
First
URLSessionTaskMetricsgathered on behalf of theRequest.Declaration
Swift
public var firstMetrics: URLSessionTaskMetrics? { get } -
Last
URLSessionTaskMetricsgathered on behalf of theRequest.Declaration
Swift
public var lastMetrics: URLSessionTaskMetrics? { get } -
Current
URLSessionTaskMetricsgathered on behalf of theRequest.Declaration
Swift
public var metrics: URLSessionTaskMetrics? { get } -
Number of times the
Requesthas been retried.Declaration
Swift
public var retryCount: Int { get } -
Errorreturned from Alamofire internally, from the network request directly, or any validators executed.Declaration
Swift
fileprivate(set) public var error: Error? { get set } -
Default initializer for the
Requestsuperclass.Declaration
Swift
public init(id: UUID = UUID(), underlyingQueue: DispatchQueue, serializationQueue: DispatchQueue, eventMonitor: EventMonitor?, interceptor: RequestInterceptor?, delegate: RequestDelegate)Parameters
idUUIDused for theHashableandEquatableimplementations. Defaults to a randomUUID.underlyingQueueDispatchQueueon which all internalRequestwork is performed.serializationQueueDispatchQueueon which all serialization work is performed. Targets theunderlyingQueuewhen created by aSessionManager.eventMonitorEventMonitorused for event callbacks from internalRequestactions.interceptorRequestInterceptorused throughout the request lifecycle.delegateRequestDelegatethat provides an interface to actions not performed by theRequest.
-
Cancels the
Request. Once cancelled, aRequestcan no longer be resumed or suspended.Declaration
Swift
@discardableResult open func cancel() -> SelfReturn Value
The
Request. -
Suspends the
Request.Declaration
Swift
@discardableResult open func suspend() -> SelfReturn Value
The
Request. -
Resumes the
Request.Declaration
Swift
@discardableResult open func resume() -> SelfReturn Value
The
Request.
-
Associates a credential using the provided values with the
Request.Declaration
Swift
@discardableResult open func authenticate(username: String, password: String, persistence: URLCredential.Persistence = .forSession) -> SelfParameters
usernameThe username.
passwordThe password.
persistenceThe
URLCredential.Persistencefor the createdURLCredential.Return Value
The
Request. -
Associates the provided credential with the
Request.Declaration
Swift
@discardableResult open func authenticate(with credential: URLCredential) -> SelfParameters
credentialThe
URLCredential.Return Value
The
Request. -
Sets a closure to be called periodically during the lifecycle of the
Requestas data is read from the server.Only the last closure provided is used.
Declaration
Swift
@discardableResult open func downloadProgress(queue: DispatchQueue = .main, closure: @escaping ProgressHandler) -> SelfParameters
queueThe
DispatchQueueto execute the closure on. Defaults to.main.closureThe code to be executed periodically as data is read from the server.
Return Value
The
Request. -
Sets a closure to be called periodically during the lifecycle of the
Requestas data is sent to the server.Only the last closure provided is used.
Declaration
Swift
@discardableResult open func uploadProgress(queue: DispatchQueue = .main, closure: @escaping ProgressHandler) -> SelfParameters
queueThe
DispatchQueueto execute the closure on. Defaults to.main.closureThe closure to be executed periodically as data is sent to the server.
Return Value
The
Request.
-
Sets the redirect handler for the
Requestwhich will be used if a redirect response is encountered.Declaration
Swift
@discardableResult open func redirect(using handler: RedirectHandler) -> SelfParameters
handlerThe
RedirectHandler.Return Value
The
Request.
-
Sets the cached response handler for the
Requestwhich will be used when attempting to cache a response.Declaration
Swift
@discardableResult open func cacheResponse(using handler: CachedResponseHandler) -> SelfParameters
handlerReturn Value
The
Request.
-
Posted when a
Requestis resumed. TheNotificationcontains the resumedRequest.Declaration
Swift
static let didResume: Notification.Name -
Posted when a
Requestis suspended. TheNotificationcontains the suspendedRequest.Declaration
Swift
static let didSuspend: Notification.Name -
Posted when a
Requestis cancelled. TheNotificationcontains the cancelledRequest.Declaration
Swift
static let didCancel: Notification.Name -
Posted when a
Requestis finished. TheNotificationcontains the completedRequest.Declaration
Swift
static let didFinish: Notification.Name
-
Declaration
Swift
public static func == (lhs: Request, rhs: Request) -> Bool
-
Declaration
Swift
public func hash(into hasher: inout Hasher)
-
A textual representation of this instance, including the
HTTPMethodandURLif theURLRequesthas been created, as well as the response status code, if a response has been received.Declaration
Swift
public var description: String { get }
-
A textual representation of this instance in the form of a cURL command.
Declaration
Swift
public var debugDescription: String { get }
-
Used to represent whether a validation succeeded or failed.
Declaration
Swift
public typealias ValidationResult = Result<Void>
View on GitHub
Install in Dash
Request Class Reference