Request
public class Request : @unchecked Sendable
extension Request: Equatable
extension Request: Hashable
extension Request: CustomStringConvertible
Request is the common superclass of all Alamofire request types and provides common state, delegate, and callback
handling.
-
UUIDproviding 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: (any EventMonitor)? -
The
Request‘s interceptor.Declaration
Swift
public let interceptor: (any RequestInterceptor)? -
The
Request‘s delegate.Declaration
Swift
public private(set) weak var delegate: (any RequestDelegate)? { get }
-
Returns whether
stateis.initialized.Declaration
Swift
public var isInitialized: Bool { get } -
Returns whether
stateis.resumed.Declaration
Swift
public var isResumed: Bool { get } -
Returns whether
stateis.suspended.Declaration
Swift
public var isSuspended: Bool { get } -
Returns whether
stateis.cancelled.Declaration
Swift
public var isCancelled: Bool { get } -
Returns whether
stateis.finished.Declaration
Swift
public var isFinished: Bool { get }
-
Closure type executed when monitoring the upload or download progress of a request.
Declaration
Swift
public typealias ProgressHandler = @Sendable (_ progress: 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 -
ProgressHandlercalled whenuploadProgressis updated, on the providedDispatchQueue.Declaration
Swift
public internal(set) var uploadProgressHandler: (handler: ProgressHandler, queue: DispatchQueue)? { get set } -
ProgressHandlercalled whendownloadProgressis updated, on the providedDispatchQueue.Declaration
Swift
public internal(set) var downloadProgressHandler: (handler: ProgressHandler, queue: DispatchQueue)? { get set }
-
RedirectHandlerset on the instance.Declaration
Swift
public internal(set) var redirectHandler: (any RedirectHandler)? { get set }
-
CachedResponseHandlerset on the instance.Declaration
Swift
public internal(set) var cachedResponseHandler: (any CachedResponseHandler)? { get set }
-
URLCredentialused for authentication challenges. Created by calling one of theauthenticatemethods.Declaration
Swift
public internal(set) var credential: URLCredential? { get set }
-
All
URLRequests created 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. May be different fromrequestsdue toURLSessionmanipulation.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
URLSessionTaskcreated 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
public internal(set) var error: AFError? { get set }
-
Cancels the instance. Once cancelled, a
Requestcan no longer be resumed or suspended.Declaration
Swift
@discardableResult public func cancel() -> SelfReturn Value
The instance.
-
Suspends the instance.
Declaration
Swift
@discardableResult public func suspend() -> SelfReturn Value
The instance.
-
Resumes the instance.
Declaration
Swift
@discardableResult public func resume() -> SelfReturn Value
The instance.
-
Associates a credential using the provided values with the instance.
Declaration
Swift
@discardableResult public func authenticate(username: String, password: String, persistence: URLCredential.Persistence = .forSession) -> SelfParameters
usernameThe username.
passwordThe password.
persistenceThe
URLCredential.Persistencefor the createdURLCredential..forSessionby default.Return Value
The instance.
-
Associates the provided credential with the instance.
Declaration
Swift
@discardableResult public func authenticate(with credential: URLCredential) -> SelfParameters
credentialThe
URLCredential.Return Value
The instance.
-
Sets a closure to be called periodically during the lifecycle of the instance as data is read from the server.
Note
Only the last closure provided is used.
Declaration
Swift
@discardableResult @preconcurrency public func downloadProgress(queue: DispatchQueue = .main, closure: @escaping ProgressHandler) -> SelfParameters
queueThe
DispatchQueueto execute the closure on..mainby default.closureThe closure to be executed periodically as data is read from the server.
Return Value
The instance.
-
Sets a closure to be called periodically during the lifecycle of the instance as data is sent to the server.
Note
Only the last closure provided is used.
Declaration
Swift
@discardableResult @preconcurrency public func uploadProgress(queue: DispatchQueue = .main, closure: @escaping ProgressHandler) -> SelfParameters
queueThe
DispatchQueueto execute the closure on..mainby default.closureThe closure to be executed periodically as data is sent to the server.
Return Value
The instance.
-
Sets the redirect handler for the instance which will be used if a redirect response is encountered.
Note
Attempting to set the redirect handler more than once is a logic error and will crash.
Declaration
Swift
@discardableResult @preconcurrency public func redirect(using handler: any RedirectHandler) -> SelfParameters
handlerThe
RedirectHandler.Return Value
The instance.
-
Sets the cached response handler for the
Requestwhich will be used when attempting to cache a response.Note
Attempting to set the cache handler more than once is a logic error and will crash.
Declaration
Swift
@discardableResult @preconcurrency public func cacheResponse(using handler: any CachedResponseHandler) -> SelfParameters
handlerReturn Value
The instance.
-
Sets a handler to be called when the cURL description of the request is available.
Note
When waiting for a
Request‘sURLRequestto be created, only the lasthandlerwill be called.Declaration
Swift
@discardableResult @preconcurrency public func cURLDescription(on queue: DispatchQueue, calling handler: @escaping @Sendable (String) -> Void) -> SelfParameters
queueDispatchQueueon whichhandlerwill be called.handlerClosure to be called when the cURL description is available.
Return Value
The instance.
-
Sets a handler to be called when the cURL description of the request is available.
Note
When waiting for a
Request‘sURLRequestto be created, only the lasthandlerwill be called.Declaration
Swift
@discardableResult @preconcurrency public func cURLDescription(calling handler: @escaping @Sendable (String) -> Void) -> SelfParameters
handlerClosure to be called when the cURL description is available. Called on the instance’s
underlyingQueueby default.Return Value
The instance.
-
Sets a closure to called whenever Alamofire creates a
URLRequestfor this instance.Note
This closure will be called multiple times if the instance adapts incoming
URLRequests or is retried.Declaration
Swift
@discardableResult @preconcurrency public func onURLRequestCreation(on queue: DispatchQueue = .main, perform handler: @escaping @Sendable (URLRequest) -> Void) -> SelfParameters
queueDispatchQueueon whichhandlerwill be called..mainby default.handlerClosure to be called when a
URLRequestis available.Return Value
The instance.
-
Sets a closure to be called whenever the instance creates a
URLSessionTask.Note
This API should only be used to provide
URLSessionTasks to existing API, likeNSFileProvider. It SHOULD NOT be used to interact with tasks directly, as that may be break Alamofire features. Additionally, this closure may be called multiple times if the instance is retried.Declaration
Swift
@discardableResult @preconcurrency public func onURLSessionTaskCreation(on queue: DispatchQueue = .main, perform handler: @escaping @Sendable (URLSessionTask) -> Void) -> SelfParameters
queueDispatchQueueon whichhandlerwill be called..mainby default.handlerClosure to be called when the
URLSessionTaskis available.Return Value
The instance.
-
Posted when a
Requestis resumed. TheNotificationcontains the resumedRequest.Declaration
Swift
public static let didResumeNotification: Notification.Name -
Posted when a
Requestis suspended. TheNotificationcontains the suspendedRequest.Declaration
Swift
public static let didSuspendNotification: Notification.Name -
Posted when a
Requestis cancelled. TheNotificationcontains the cancelledRequest.Declaration
Swift
public static let didCancelNotification: Notification.Name -
Posted when a
Requestis finished. TheNotificationcontains the completedRequest.Declaration
Swift
public static let didFinishNotification: Notification.Name -
Posted when a
URLSessionTaskis resumed. TheNotificationcontains theRequestassociated with theURLSessionTask.Declaration
Swift
public static let didResumeTaskNotification: Notification.Name -
Posted when a
URLSessionTaskis suspended. TheNotificationcontains theRequestassociated with theURLSessionTask.Declaration
Swift
public static let didSuspendTaskNotification: Notification.Name -
Posted when a
URLSessionTaskis cancelled. TheNotificationcontains theRequestassociated with theURLSessionTask.Declaration
Swift
public static let didCancelTaskNotification: Notification.Name -
Posted when a
URLSessionTaskis completed. TheNotificationcontains theRequestassociated with theURLSessionTask.Declaration
Swift
public static let didCompleteTaskNotification: Notification.Name -
Type indicating how a
See moreDataRequestorDataStreamRequestshould proceed after receiving anHTTPURLResponse.Declaration
Swift
public enum ResponseDisposition : Sendable
-
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 } -
cURL representation of the instance.
Declaration
Swift
public func cURLDescription() -> StringReturn Value
The cURL equivalent of the instance.
-
Creates a
StreamOf<Progress>for the instance’s upload progress.Declaration
Parameters
bufferingPolicyBufferingPolicythat determines the stream’s buffering behavior..unboundedby default.Return Value
The
StreamOf<Progress>. -
Creates a
StreamOf<Progress>for the instance’s download progress.Declaration
Parameters
bufferingPolicyBufferingPolicythat determines the stream’s buffering behavior..unboundedby default.Return Value
The
StreamOf<Progress>. -
Creates a
StreamOf<URLRequest>for theURLRequests produced for the instance.Declaration
Parameters
bufferingPolicyBufferingPolicythat determines the stream’s buffering behavior..unboundedby default.Return Value
The
StreamOf<URLRequest>. -
Creates a
StreamOf<URLSessionTask>for theURLSessionTasks produced for the instance.Declaration
Parameters
bufferingPolicyBufferingPolicythat determines the stream’s buffering behavior..unboundedby default.Return Value
-
Creates a
StreamOf<String>for the cURL descriptions produced for the instance.Declaration
Parameters
bufferingPolicyBufferingPolicythat determines the stream’s buffering behavior..unboundedby default.Return Value
The
StreamOf<String>.
-
Used to represent whether a validation succeeded or failed.
Declaration
Swift
public typealias ValidationResult = Result<Void, any (Error & Sendable)>
View on GitHub
Install in Dash