docs/Classes/DownloadRequest.html
public final class DownloadRequest : Request, @unchecked Sendable
Request subclass which downloads Data to a file on disk using URLSessionDownloadTask.
`
Options
`
A set of options to be executed prior to moving a downloaded file from the temporary URL to the destination URL.
Swift
public struct Options : OptionSet, Sendable
`
Destination
`
A closure executed once a DownloadRequest has successfully completed in order to determine where to move the temporary file written to during the download process. The closure takes two arguments: the temporary file URL and the HTTPURLResponse, and returns two values: the file URL where the temporary file should be moved and the options defining how the file should be moved.
Note
Downloads from a local file:// URLs do not use the Destination closure, as those downloads do not return an HTTPURLResponse. Instead the file is merely moved within the temporary directory.
Swift
public typealias Destination = @Sendable (_ temporaryURL: URL,
_ response: HTTPURLResponse) -> (destinationURL: URL, options: Options)
`
suggestedDownloadDestination(for:in:options:)
`
Creates a download file destination closure which uses the default file manager to move the temporary file to a file URL in the first available directory with the specified search path directory and search path domain mask.
Swift
public class func suggestedDownloadDestination(for directory: FileManager.SearchPathDirectory = .documentDirectory,
in domain: FileManager.SearchPathDomainMask = .userDomainMask,
options: Options = []) -> Destination
| directory |
The search path directory. .documentDirectory by default.
|
| domain |
The search path domain mask. .userDomainMask by default.
|
| options |
DownloadRequest.Options used when moving the downloaded file to its destination. None by default.
|
The Destination closure.
`
Downloadable
`
Type describing the source used to create the underlying URLSessionDownloadTask.
Swift
public enum Downloadable
`
resumeData
`
If the download is resumable and is eventually cancelled or fails, this value may be used to resume the download using the download(resumingWith data:) API.
Note
For more information about resumeData, see Apple’s documentation.
Swift
public var resumeData: Data? { get }
`
fileURL
`
If the download is successful, the URL where the file was downloaded.
Swift
public var fileURL: URL? { get }
`
downloadable
`
Downloadable value used for this instance.
Swift
public let downloadable: Downloadable
`
task(forResumeData:using:)
`
Creates a URLSessionTask from the provided resume data.
Swift
public func task(forResumeData data: Data, using session: URLSession) -> URLSessionTask
| data |
Data used to resume the download.
|
| session |
URLSession used to create the URLSessionTask.
|
The URLSessionTask created.
`
cancel()
`
Cancels the instance. Once cancelled, a DownloadRequest can no longer be resumed or suspended.
Note
This method will NOT produce resume data. If you wish to cancel and produce resume data, use cancel(producingResumeData:) or cancel(byProducingResumeData:).
Swift
@discardableResult
override public func cancel() -> Self
The instance.
`
cancel(producingResumeData:)
`
Cancels the instance, optionally producing resume data. Once cancelled, a DownloadRequest can no longer be resumed or suspended.
Note
If producingResumeData is true, the resumeData property will be populated with any resume data, if available.
Swift
@discardableResult
public func cancel(producingResumeData shouldProduceResumeData: Bool) -> Self
The instance.
`
cancel(byProducingResumeData:)
`
Cancels the instance while producing resume data. Once cancelled, a DownloadRequest can no longer be resumed or suspended.
Note
The resume data passed to the completion handler will also be available on the instance’s resumeData property.
Swift
@discardableResult
@preconcurrency
public func cancel(byProducingResumeData completionHandler: @escaping @Sendable (_ data: Data?) -> Void) -> Self
| completionHandler |
The completion handler that is called when the download has been successfully cancelled. It is not guaranteed to be called on a particular queue, so you may want use an appropriate queue to perform your work.
|
The instance.
`
validate(_:)
`
Validates the request, using the specified closure.
Note
If validation fails, subsequent calls to response handlers will have an associated error.
Swift
@discardableResult
public func validate(_ validation: @escaping Validation) -> Self
| validation |
Validation closure to validate the response.
|
The instance.
`
response(queue:completionHandler:)
`
Adds a handler to be called once the request has finished.
Swift
@discardableResult
@preconcurrency
public func response(queue: DispatchQueue = .main,
completionHandler: @escaping @Sendable (AFDownloadResponse<URL?>) -> Void)
-> Self
| queue |
The queue on which the completion handler is dispatched. .main by default.
|
| completionHandler |
The code to be executed once the request has finished.
|
The request.
`
response(queue:responseSerializer:completionHandler:)
`
Adds a handler to be called once the request has finished.
Note
This handler will read the entire downloaded file into memory, use with caution.
Swift
@discardableResult
public func response<Serializer: DownloadResponseSerializerProtocol>(queue: DispatchQueue = .main,
responseSerializer: Serializer,
completionHandler: @escaping @Sendable (AFDownloadResponse<Serializer.SerializedObject>) -> Void)
-> Self
| queue |
The queue on which the completion handler is dispatched. .main by default.
|
| responseSerializer |
The response serializer responsible for serializing the request, response, and data contained in the destination URL.
|
| completionHandler |
The code to be executed once the request has finished.
|
The request.
`
response(queue:responseSerializer:completionHandler:)
`
Adds a handler to be called once the request has finished.
Note
This handler will read the entire downloaded file into memory, use with caution.
Swift
@discardableResult
public func response<Serializer: ResponseSerializer>(queue: DispatchQueue = .main,
responseSerializer: Serializer,
completionHandler: @escaping @Sendable (AFDownloadResponse<Serializer.SerializedObject>) -> Void)
-> Self
| queue |
The queue on which the completion handler is dispatched. .main by default.
|
| responseSerializer |
The response serializer responsible for serializing the request, response, and data contained in the destination URL.
|
| completionHandler |
The code to be executed once the request has finished.
|
The request.
`
responseURL(queue:completionHandler:)
`
Adds a handler using a URLResponseSerializer to be called once the request is finished.
Swift
@discardableResult
@preconcurrency
public func responseURL(queue: DispatchQueue = .main,
completionHandler: @escaping @Sendable (AFDownloadResponse<URL>) -> Void) -> Self
| queue |
The queue on which the completion handler is called. .main by default.
|
| completionHandler |
A closure to be executed once the request has finished.
|
The request.
`
responseData(queue:dataPreprocessor:emptyResponseCodes:emptyRequestMethods:completionHandler:)
`
Adds a handler using a DataResponseSerializer to be called once the request has finished.
Note
This handler will read the entire downloaded file into memory, use with caution.
Swift
@discardableResult
@preconcurrency
public func responseData(queue: DispatchQueue = .main,
dataPreprocessor: any DataPreprocessor = DataResponseSerializer.defaultDataPreprocessor,
emptyResponseCodes: Set<Int> = DataResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = DataResponseSerializer.defaultEmptyRequestMethods,
completionHandler: @escaping @Sendable (AFDownloadResponse<Data>) -> Void) -> Self
| queue |
The queue on which the completion handler is called. .main by default.
|
| dataPreprocessor |
DataPreprocessor which processes the received Data before calling the completionHandler. PassthroughPreprocessor() by default.
|
| emptyResponseCodes |
HTTP status codes for which empty responses are always valid. [204, 205] by default.
|
| emptyRequestMethods |
HTTPMethods for which empty responses are always valid. [.head] by default.
|
| completionHandler |
A closure to be executed once the request has finished.
|
The request.
`
responseString(queue:dataPreprocessor:encoding:emptyResponseCodes:emptyRequestMethods:completionHandler:)
`
Adds a handler using a StringResponseSerializer to be called once the request has finished.
Note
This handler will read the entire downloaded file into memory, use with caution.
Swift
@discardableResult
@preconcurrency
public func responseString(queue: DispatchQueue = .main,
dataPreprocessor: any DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor,
encoding: String.Encoding? = nil,
emptyResponseCodes: Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods,
completionHandler: @escaping @Sendable (AFDownloadResponse<String>) -> Void) -> Self
| queue |
The queue on which the completion handler is dispatched. .main by default.
|
| dataPreprocessor |
DataPreprocessor which processes the received Data before calling the completionHandler. PassthroughPreprocessor() by default.
|
| encoding |
The string encoding. Defaults to nil, in which case the encoding will be determined from the server response, falling back to the default HTTP character set, ISO-8859-1.
|
| emptyResponseCodes |
HTTP status codes for which empty responses are always valid. [204, 205] by default.
|
| emptyRequestMethods |
HTTPMethods for which empty responses are always valid. [.head] by default.
|
| completionHandler |
A closure to be executed once the request has finished.
|
The request.
`
responseJSON(queue:dataPreprocessor:emptyResponseCodes:emptyRequestMethods:options:completionHandler:)
`
Adds a handler using a JSONResponseSerializer to be called once the request has finished.
Note
This handler will read the entire downloaded file into memory, use with caution.
Swift
@available(*, deprecated, message: "responseJSON deprecated and will be removed in Alamofire 6. Use responseDecodable instead.")
@discardableResult
@preconcurrency
public func responseJSON(queue: DispatchQueue = .main,
dataPreprocessor: any DataPreprocessor = JSONResponseSerializer.defaultDataPreprocessor,
emptyResponseCodes: Set<Int> = JSONResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = JSONResponseSerializer.defaultEmptyRequestMethods,
options: JSONSerialization.ReadingOptions = .allowFragments,
completionHandler: @escaping @Sendable (AFDownloadResponse<Any>) -> Void) -> Self
| queue |
The queue on which the completion handler is dispatched. .main by default.
|
| dataPreprocessor |
DataPreprocessor which processes the received Data before calling the completionHandler. PassthroughPreprocessor() by default.
|
| emptyResponseCodes |
HTTP status codes for which empty responses are always valid. [204, 205] by default.
|
| emptyRequestMethods |
HTTPMethods for which empty responses are always valid. [.head] by default.
|
| options |
JSONSerialization.ReadingOptions used when parsing the response. .allowFragments by default.
|
| completionHandler |
A closure to be executed once the request has finished.
|
The request.
`
responseDecodable(of:queue:dataPreprocessor:decoder:emptyResponseCodes:emptyRequestMethods:completionHandler:)
`
Adds a handler using a DecodableResponseSerializer to be called once the request has finished.
Note
This handler will read the entire downloaded file into memory, use with caution.
Swift
@discardableResult
@preconcurrency
public func responseDecodable<T: Decodable>(of type: T.Type = T.self,
queue: DispatchQueue = .main,
dataPreprocessor: any DataPreprocessor = DecodableResponseSerializer<T>.defaultDataPreprocessor,
decoder: any DataDecoder = JSONDecoder(),
emptyResponseCodes: Set<Int> = DecodableResponseSerializer<T>.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = DecodableResponseSerializer<T>.defaultEmptyRequestMethods,
completionHandler: @escaping @Sendable (AFDownloadResponse<T>) -> Void) -> Self where T: Sendable
| type |
Decodable type to decode from response data.
|
| queue |
The queue on which the completion handler is dispatched. .main by default.
|
| dataPreprocessor |
DataPreprocessor which processes the received Data before calling the completionHandler. PassthroughPreprocessor() by default.
|
| decoder |
DataDecoder to use to decode the response. JSONDecoder() by default.
|
| emptyResponseCodes |
HTTP status codes for which empty responses are always valid. [204, 205] by default.
|
| emptyRequestMethods |
HTTPMethods for which empty responses are always valid. [.head] by default.
|
| completionHandler |
A closure to be executed once the request has finished.
|
The request.
`
publishResponse(using:on:)
`
Creates a DownloadResponsePublisher for this instance using the given ResponseSerializer and DispatchQueue.
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
public func publishResponse<Serializer: ResponseSerializer, T>(using serializer: Serializer, on queue: DispatchQueue = .main) -> DownloadResponsePublisher<T>
where Serializer.SerializedObject == T
| serializer |
ResponseSerializer used to serialize the response Data from disk.
|
| queue |
DispatchQueue on which the DownloadResponse will be published..main by default.
|
The DownloadResponsePublisher.
`
publishResponse(using:on:)
`
Creates a DownloadResponsePublisher for this instance using the given DownloadResponseSerializerProtocol and DispatchQueue.
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
public func publishResponse<Serializer: DownloadResponseSerializerProtocol, T>(using serializer: Serializer, on queue: DispatchQueue = .main) -> DownloadResponsePublisher<T>
where Serializer.SerializedObject == T
| serializer |
DownloadResponseSerializer used to serialize the response Data from disk.
|
| queue |
DispatchQueue on which the DownloadResponse will be published..main by default.
|
The DownloadResponsePublisher.
`
publishURL(queue:)
`
Creates a DownloadResponsePublisher for this instance and uses a URLResponseSerializer to serialize the response.
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
public func publishURL(queue: DispatchQueue = .main) -> DownloadResponsePublisher<URL>
| queue |
DispatchQueue on which the DownloadResponse will be published. .main by default.
|
The DownloadResponsePublisher.
`
publishData(queue:preprocessor:emptyResponseCodes:emptyRequestMethods:)
`
Creates a DownloadResponsePublisher for this instance and uses a DataResponseSerializer to serialize the response.
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
public func publishData(queue: DispatchQueue = .main,
preprocessor: any DataPreprocessor = DataResponseSerializer.defaultDataPreprocessor,
emptyResponseCodes: Set<Int> = DataResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = DataResponseSerializer.defaultEmptyRequestMethods) -> DownloadResponsePublisher<Data>
| queue |
DispatchQueue on which the DownloadResponse will be published. .main by default.
|
| preprocessor |
DataPreprocessor which filters the Data before serialization. PassthroughPreprocessor() by default.
|
| emptyResponseCodes |
Set<Int> of HTTP status codes for which empty responses are allowed. [204, 205] by default.
|
| emptyRequestMethods |
Set<HTTPMethod> of HTTPMethods for which empty responses are allowed, regardless of status code. [.head] by default.
|
The DownloadResponsePublisher.
`
publishString(queue:preprocessor:encoding:emptyResponseCodes:emptyRequestMethods:)
`
Creates a DownloadResponsePublisher for this instance and uses a StringResponseSerializer to serialize the response.
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
public func publishString(queue: DispatchQueue = .main,
preprocessor: any DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor,
encoding: String.Encoding? = nil,
emptyResponseCodes: Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods) -> DownloadResponsePublisher<String>
| queue |
DispatchQueue on which the DataResponse will be published. .main by default.
|
| preprocessor |
DataPreprocessor which filters the Data before serialization. PassthroughPreprocessor() by default.
|
| encoding |
String.Encoding to parse the response. nil by default, in which case the encoding will be determined by the server response, falling back to the default HTTP character set, ISO-8859-1.
|
| emptyResponseCodes |
Set<Int> of HTTP status codes for which empty responses are allowed. [204, 205] by default.
|
| emptyRequestMethods |
Set<HTTPMethod> of HTTPMethods for which empty responses are allowed, regardless of status code. [.head] by default.
|
The DownloadResponsePublisher.
`
publishDecodable(type:queue:preprocessor:decoder:emptyResponseCodes:emptyResponseMethods:)
`
Undocumented
Swift
@_disfavoredOverload
public func publishDecodable<T: Decodable>(type: T.Type = T.self,
queue: DispatchQueue = .main,
preprocessor: any DataPreprocessor = DecodableResponseSerializer<T>.defaultDataPreprocessor,
decoder: any DataDecoder = JSONDecoder(),
emptyResponseCodes: Set<Int> = DecodableResponseSerializer<T>.defaultEmptyResponseCodes,
emptyResponseMethods: Set<HTTPMethod> = DecodableResponseSerializer<T>.defaultEmptyRequestMethods) -> DownloadResponsePublisher<T>
`
publishDecodable(type:queue:preprocessor:decoder:emptyResponseCodes:emptyRequestMethods:)
`
Creates a DownloadResponsePublisher for this instance and uses a DecodableResponseSerializer to serialize the response.
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
public func publishDecodable<T: Decodable>(type: T.Type = T.self,
queue: DispatchQueue = .main,
preprocessor: any DataPreprocessor = DecodableResponseSerializer<T>.defaultDataPreprocessor,
decoder: any DataDecoder = JSONDecoder(),
emptyResponseCodes: Set<Int> = DecodableResponseSerializer<T>.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = DecodableResponseSerializer<T>.defaultEmptyRequestMethods) -> DownloadResponsePublisher<T>
| type |
Decodable type to which to decode response Data. Inferred from the context by default.
|
| queue |
DispatchQueue on which the DataResponse will be published. .main by default.
|
| preprocessor |
DataPreprocessor which filters the Data before serialization. PassthroughPreprocessor() by default.
|
| decoder |
DataDecoder instance used to decode response Data. JSONDecoder() by default.
|
| emptyResponseCodes |
Set<Int> of HTTP status codes for which empty responses are allowed. [204, 205] by default.
|
| emptyRequestMethods |
Set<HTTPMethod> of HTTPMethods for which empty responses are allowed, regardless of status code. [.head] by default.
|
The DownloadResponsePublisher.
`
publishUnserialized(on:)
`
Creates a DownloadResponsePublisher for this instance which does not serialize the response before publishing.
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
public func publishUnserialized(on queue: DispatchQueue = .main) -> DownloadResponsePublisher<URL?>
| queue |
DispatchQueue on which the DownloadResponse will be published. .main by default.
|
The DownloadResponsePublisher.
`
serializingData(automaticallyCancelling:dataPreprocessor:emptyResponseCodes:emptyRequestMethods:)
`
Creates a DownloadTask to await a Data value.
Swift
public func serializingData(automaticallyCancelling shouldAutomaticallyCancel: Bool = true,
dataPreprocessor: any DataPreprocessor = DataResponseSerializer.defaultDataPreprocessor,
emptyResponseCodes: Set<Int> = DataResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = DataResponseSerializer.defaultEmptyRequestMethods) -> DownloadTask<Data>
| shouldAutomaticallyCancel |
Bool determining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies to DownloadTask‘s async properties. true by default.
|
| dataPreprocessor |
DataPreprocessor which processes the received Data before completion.
|
| emptyResponseCodes |
HTTP response codes for which empty responses are allowed. [204, 205] by default.
|
| emptyRequestMethods |
HTTPMethods for which empty responses are always valid. [.head] by default.
|
The DownloadTask.
`
serializingDecodable(_:automaticallyCancelling:dataPreprocessor:decoder:emptyResponseCodes:emptyRequestMethods:)
`
Creates a DownloadTask to await serialization of a Decodable value.
Note
This serializer reads the entire response into memory before parsing.
Swift
public func serializingDecodable<Value: Decodable>(_ type: Value.Type = Value.self,
automaticallyCancelling shouldAutomaticallyCancel: Bool = true,
dataPreprocessor: any DataPreprocessor = DecodableResponseSerializer<Value>.defaultDataPreprocessor,
decoder: any DataDecoder = JSONDecoder(),
emptyResponseCodes: Set<Int> = DecodableResponseSerializer<Value>.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = DecodableResponseSerializer<Value>.defaultEmptyRequestMethods) -> DownloadTask<Value>
| type |
Decodable type to decode from response data.
|
| shouldAutomaticallyCancel |
Bool determining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies to DownloadTask‘s async properties. true by default.
|
| dataPreprocessor |
DataPreprocessor which processes the received Data before calling the serializer. PassthroughPreprocessor() by default.
|
| decoder |
DataDecoder to use to decode the response. JSONDecoder() by default.
|
| emptyResponseCodes |
HTTP status codes for which empty responses are always valid. [204, 205] by default.
|
| emptyRequestMethods |
HTTPMethods for which empty responses are always valid. [.head] by default.
|
The DownloadTask.
`
serializingDownloadedFileURL(automaticallyCancelling:)
`
Creates a DownloadTask to await serialization of the downloaded file’s URL on disk.
Swift
public func serializingDownloadedFileURL(automaticallyCancelling shouldAutomaticallyCancel: Bool = true) -> DownloadTask<URL>
| shouldAutomaticallyCancel |
Bool determining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies to DownloadTask‘s async properties. true by default.
|
The DownloadTask.
`
serializingString(automaticallyCancelling:dataPreprocessor:encoding:emptyResponseCodes:emptyRequestMethods:)
`
Creates a DownloadTask to await serialization of a String value.
Swift
public func serializingString(automaticallyCancelling shouldAutomaticallyCancel: Bool = true,
dataPreprocessor: any DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor,
encoding: String.Encoding? = nil,
emptyResponseCodes: Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes,
emptyRequestMethods: Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods) -> DownloadTask<String>
| shouldAutomaticallyCancel |
Bool determining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies to DownloadTask‘s async properties. true by default.
|
| dataPreprocessor |
DataPreprocessor which processes the received Data before calling the serializer. PassthroughPreprocessor() by default.
|
| encoding |
String.Encoding to use during serialization. Defaults to nil, in which case the encoding will be determined from the server response, falling back to the default HTTP character set, ISO-8859-1.
|
| emptyResponseCodes |
HTTP status codes for which empty responses are always valid. [204, 205] by default.
|
| emptyRequestMethods |
HTTPMethods for which empty responses are always valid. [.head] by default.
|
The DownloadTask.
`
serializingDownload(using:automaticallyCancelling:)
`
Creates a DownloadTask to await serialization using the provided ResponseSerializer instance.
Swift
public func serializingDownload<Serializer: ResponseSerializer>(using serializer: Serializer,
automaticallyCancelling shouldAutomaticallyCancel: Bool = true)
-> DownloadTask<Serializer.SerializedObject>
| serializer |
ResponseSerializer responsible for serializing the request, response, and data.
|
| shouldAutomaticallyCancel |
Bool determining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies to DownloadTask‘s async properties. true by default.
|
The DownloadTask.
`
serializingDownload(using:automaticallyCancelling:)
`
Creates a DownloadTask to await serialization using the provided DownloadResponseSerializerProtocol instance.
Swift
public func serializingDownload<Serializer: DownloadResponseSerializerProtocol>(using serializer: Serializer,
automaticallyCancelling shouldAutomaticallyCancel: Bool = true)
-> DownloadTask<Serializer.SerializedObject>
| serializer |
DownloadResponseSerializerProtocol responsible for serializing the request, response, and data.
|
| shouldAutomaticallyCancel |
Bool determining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies to DownloadTask‘s async properties. true by default.
|
The DownloadTask.
`
Validation
`
A closure used to validate a request that takes a URL request, a URL response, a temporary URL and a destination URL, and returns whether the request was valid.
Swift
public typealias Validation = @Sendable (_ request: URLRequest?,
_ response: HTTPURLResponse,
_ fileURL: URL?)
-> ValidationResult
`
validate(statusCode:)
`
Validates that the response has a status code in the specified sequence.
If validation fails, subsequent calls to response handlers will have an associated error.
Swift
@discardableResult
@preconcurrency
public func validate<S>(statusCode acceptableStatusCodes: S) -> Self where S : Sendable, S : Sequence, S.Element == Int
| acceptableStatusCodes |
Sequence of acceptable response status codes.
|
The instance.
`
validate(contentType:)
`
Validates that the response has a Content-Type in the specified sequence.
If validation fails, subsequent calls to response handlers will have an associated error.
Swift
@discardableResult
@preconcurrency
public func validate<S>(contentType acceptableContentTypes: @escaping @Sendable @autoclosure () -> S) -> Self where S : Sendable, S : Sequence, S.Element == String
| contentType |
The acceptable content types, which may specify wildcard types and/or subtypes.
|
The request.
`
validate()
`
Validates that the response has a status code in the default acceptable range of 200…299, and that the content type matches any specified in the Accept HTTP header field.
If validation fails, subsequent calls to response handlers will have an associated error.
Swift
@discardableResult
public func validate() -> Self
The request.