-
URLRequestConvertiblevalue used to createURLRequests for this instance.Declaration
Swift
public let convertible: URLRequestConvertible -
Dataread from the server so far.Declaration
Swift
public var data: Data? { get } -
Validates the request, using the specified closure.
Note
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate(_ validation: @escaping Validation) -> SelfParameters
validationValidationclosure used to validate the response.Return Value
The instance.
-
Creates a
DataResponsePublisherfor this instance using the givenResponseSerializerandDispatchQueue.Declaration
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) public func publishResponse<Serializer: ResponseSerializer, T>(using serializer: Serializer, on queue: DispatchQueue = .main) -> DataResponsePublisher<T> where Serializer.SerializedObject == TParameters
serializerResponseSerializerused to serialize responseData.queueDispatchQueueon which theDataResponsewill be published..mainby default.Return Value
-
Creates a
DataResponsePublisherfor this instance and uses aDataResponseSerializerto serialize the response.Declaration
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) public func publishData(queue: DispatchQueue = .main, preprocessor: DataPreprocessor = DataResponseSerializer.defaultDataPreprocessor, emptyResponseCodes: Set<Int> = DataResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = DataResponseSerializer.defaultEmptyRequestMethods) -> DataResponsePublisher<Data>Parameters
queueDispatchQueueon which theDataResponsewill be published..mainby default.preprocessorDataPreprocessorwhich filters theDatabefore serialization.PassthroughPreprocessor()by default.emptyResponseCodesSet<Int>of HTTP status codes for which empty responses are allowed.[204, 205]by default.emptyRequestMethodsSet<HTTPMethod>ofHTTPMethods for which empty responses are allowed, regardless of status code.[.head]by default.Return Value
-
Creates a
DataResponsePublisherfor this instance and uses aStringResponseSerializerto serialize the response.Declaration
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) public func publishString(queue: DispatchQueue = .main, preprocessor: DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor, encoding: String.Encoding? = nil, emptyResponseCodes: Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods) -> DataResponsePublisher<String>Parameters
queueDispatchQueueon which theDataResponsewill be published..mainby default.preprocessorDataPreprocessorwhich filters theDatabefore serialization.PassthroughPreprocessor()by default.encodingString.Encodingto parse the response.nilby default, in which case the encoding will be determined by the server response, falling back to the default HTTP character set,ISO-8859-1.emptyResponseCodesSet<Int>of HTTP status codes for which empty responses are allowed.[204, 205]by default.emptyRequestMethodsSet<HTTPMethod>ofHTTPMethods for which empty responses are allowed, regardless of status code.[.head]by default.Return Value
-
Undocumented
Declaration
Swift
@_disfavoredOverload public func publishDecodable<T: Decodable>(type: T.Type = T.self, queue: DispatchQueue = .main, preprocessor: DataPreprocessor = DecodableResponseSerializer<T>.defaultDataPreprocessor, decoder: DataDecoder = JSONDecoder(), emptyResponseCodes: Set<Int> = DecodableResponseSerializer<T>.defaultEmptyResponseCodes, emptyResponseMethods: Set<HTTPMethod> = DecodableResponseSerializer<T>.defaultEmptyRequestMethods) -> DataResponsePublisher<T> -
Creates a
DataResponsePublisherfor this instance and uses aDecodableResponseSerializerto serialize the response.Declaration
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: DataPreprocessor = DecodableResponseSerializer<T>.defaultDataPreprocessor, decoder: DataDecoder = JSONDecoder(), emptyResponseCodes: Set<Int> = DecodableResponseSerializer<T>.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = DecodableResponseSerializer<T>.defaultEmptyRequestMethods) -> DataResponsePublisher<T>Parameters
typeDecodabletype to which to decode responseData. Inferred from the context by default.queueDispatchQueueon which theDataResponsewill be published..mainby default.preprocessorDataPreprocessorwhich filters theDatabefore serialization.PassthroughPreprocessor()by default.decoderDataDecoderinstance used to decode responseData.JSONDecoder()by default.emptyResponseCodesSet<Int>of HTTP status codes for which empty responses are allowed.[204, 205]by default.emptyRequestMethodsSet<HTTPMethod>ofHTTPMethods for which empty responses are allowed, regardless of status code.[.head]by default.Return Value
-
Creates a
DataResponsePublisherfor this instance which does not serialize the response before publishing.queue:
DispatchQueueon which theDataResponsewill be published..mainby default.
Declaration
Swift
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) public func publishUnserialized(queue: DispatchQueue = .main) -> DataResponsePublisher<Data?>Return Value
-
Creates a
DataTasktoawaitaDatavalue.Declaration
Swift
public func serializingData(automaticallyCancelling shouldAutomaticallyCancel: Bool = false, dataPreprocessor: DataPreprocessor = DataResponseSerializer.defaultDataPreprocessor, emptyResponseCodes: Set<Int> = DataResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = DataResponseSerializer.defaultEmptyRequestMethods) -> DataTask<Data>Parameters
shouldAutomaticallyCancelBooldetermining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies toDataTask‘s async properties.falseby default.dataPreprocessorDataPreprocessorwhich processes the receivedDatabefore completion.emptyResponseCodesHTTP response codes for which empty responses are allowed.
[204, 205]by default.emptyRequestMethodsHTTPMethods for which empty responses are always valid.[.head]by default.Return Value
The
DataTask. -
serializingDecodable(_:automaticallyCancelling: dataPreprocessor: decoder: emptyResponseCodes: emptyRequestMethods: ) Creates a
DataTasktoawaitserialization of aDecodablevalue.Declaration
Swift
public func serializingDecodable<Value: Decodable>(_ type: Value.Type = Value.self, automaticallyCancelling shouldAutomaticallyCancel: Bool = false, dataPreprocessor: DataPreprocessor = DecodableResponseSerializer<Value>.defaultDataPreprocessor, decoder: DataDecoder = JSONDecoder(), emptyResponseCodes: Set<Int> = DecodableResponseSerializer<Value>.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = DecodableResponseSerializer<Value>.defaultEmptyRequestMethods) -> DataTask<Value>Parameters
typeDecodabletype to decode from response data.shouldAutomaticallyCancelBooldetermining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies toDataTask‘s async properties.falseby default.dataPreprocessorDataPreprocessorwhich processes the receivedDatabefore calling the serializer.PassthroughPreprocessor()by default.decoderDataDecoderto use to decode the response.JSONDecoder()by default.emptyResponseCodesHTTP status codes for which empty responses are always valid.
[204, 205]by default.emptyRequestMethodsHTTPMethods for which empty responses are always valid.[.head]by default.Return Value
The
DataTask. -
serializingString(automaticallyCancelling:dataPreprocessor: encoding: emptyResponseCodes: emptyRequestMethods: ) Creates a
DataTasktoawaitserialization of aStringvalue.Declaration
Swift
public func serializingString(automaticallyCancelling shouldAutomaticallyCancel: Bool = false, dataPreprocessor: DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor, encoding: String.Encoding? = nil, emptyResponseCodes: Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods) -> DataTask<String>Parameters
shouldAutomaticallyCancelBooldetermining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies toDataTask‘s async properties.falseby default.dataPreprocessorDataPreprocessorwhich processes the receivedDatabefore calling the serializer.PassthroughPreprocessor()by default.encodingString.Encodingto use during serialization. Defaults tonil, in which case the encoding will be determined from the server response, falling back to the default HTTP character set,ISO-8859-1.emptyResponseCodesHTTP status codes for which empty responses are always valid.
[204, 205]by default.emptyRequestMethodsHTTPMethods for which empty responses are always valid.[.head]by default.Return Value
The
DataTask. -
Creates a
DataTasktoawaitserialization using the providedResponseSerializerinstance.Declaration
Swift
public func serializingResponse<Serializer: ResponseSerializer>(using serializer: Serializer, automaticallyCancelling shouldAutomaticallyCancel: Bool = false) -> DataTask<Serializer.SerializedObject>Parameters
serializerResponseSerializerresponsible for serializing the request, response, and data.shouldAutomaticallyCancelBooldetermining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies toDataTask‘s async properties.falseby default.Return Value
The
DataTask. -
Creates a
DataTasktoawaitserialization using the providedDataResponseSerializerProtocolinstance.Declaration
Swift
public func serializingResponse<Serializer: DataResponseSerializerProtocol>(using serializer: Serializer, automaticallyCancelling shouldAutomaticallyCancel: Bool = false) -> DataTask<Serializer.SerializedObject>Parameters
serializerDataResponseSerializerProtocolresponsible for serializing the request, response, and data.shouldAutomaticallyCancelBooldetermining whether or not the request should be cancelled when the enclosing async context is cancelled. Only applies toDataTask‘s async properties.falseby default.Return Value
The
DataTask.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func response(queue: DispatchQueue = .main, completionHandler: @escaping (AFDataResponse<Data?>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby default.completionHandlerThe code to be executed once the request has finished.
Return Value
The request.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func response<Serializer: DataResponseSerializerProtocol>(queue: DispatchQueue = .main, responseSerializer: Serializer, completionHandler: @escaping (AFDataResponse<Serializer.SerializedObject>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby defaultresponseSerializerThe response serializer responsible for serializing the request, response, and data.
completionHandlerThe code to be executed once the request has finished.
Return Value
The request.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func response<Serializer: ResponseSerializer>(queue: DispatchQueue = .main, responseSerializer: Serializer, completionHandler: @escaping (AFDataResponse<Serializer.SerializedObject>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby defaultresponseSerializerThe response serializer responsible for serializing the request, response, and data.
completionHandlerThe code to be executed once the request has finished.
Return Value
The request.
-
Adds a handler using a
DataResponseSerializerto be called once the request has finished.Declaration
Swift
@discardableResult public func responseData(queue: DispatchQueue = .main, dataPreprocessor: DataPreprocessor = DataResponseSerializer.defaultDataPreprocessor, emptyResponseCodes: Set<Int> = DataResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = DataResponseSerializer.defaultEmptyRequestMethods, completionHandler: @escaping (AFDataResponse<Data>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is called.
.mainby default.dataPreprocessorDataPreprocessorwhich processes the receivedDatabefore calling thecompletionHandler.PassthroughPreprocessor()by default.emptyResponseCodesHTTP status codes for which empty responses are always valid.
[204, 205]by default.emptyRequestMethodsHTTPMethods for which empty responses are always valid.[.head]by default.completionHandlerA closure to be executed once the request has finished.
Return Value
The request.
-
responseString(queue:dataPreprocessor: encoding: emptyResponseCodes: emptyRequestMethods: completionHandler: ) Adds a handler using a
StringResponseSerializerto be called once the request has finished.Declaration
Swift
@discardableResult public func responseString(queue: DispatchQueue = .main, dataPreprocessor: DataPreprocessor = StringResponseSerializer.defaultDataPreprocessor, encoding: String.Encoding? = nil, emptyResponseCodes: Set<Int> = StringResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = StringResponseSerializer.defaultEmptyRequestMethods, completionHandler: @escaping (AFDataResponse<String>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby default.dataPreprocessorDataPreprocessorwhich processes the receivedDatabefore calling thecompletionHandler.PassthroughPreprocessor()by default.encodingThe 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.emptyResponseCodesHTTP status codes for which empty responses are always valid.
[204, 205]by default.emptyRequestMethodsHTTPMethods for which empty responses are always valid.[.head]by default.completionHandlerA closure to be executed once the request has finished.
Return Value
The request.
-
responseJSON(queue:dataPreprocessor: emptyResponseCodes: emptyRequestMethods: options: completionHandler: ) Adds a handler using a
JSONResponseSerializerto be called once the request has finished.Declaration
Swift
@available(*, deprecated, message: "responseJSON deprecated and will be removed in Alamofire 6. Use responseDecodable instead.") @discardableResult public func responseJSON(queue: DispatchQueue = .main, dataPreprocessor: DataPreprocessor = JSONResponseSerializer.defaultDataPreprocessor, emptyResponseCodes: Set<Int> = JSONResponseSerializer.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = JSONResponseSerializer.defaultEmptyRequestMethods, options: JSONSerialization.ReadingOptions = .allowFragments, completionHandler: @escaping (AFDataResponse<Any>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby default.dataPreprocessorDataPreprocessorwhich processes the receivedDatabefore calling thecompletionHandler.PassthroughPreprocessor()by default.encodingThe 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.emptyResponseCodesHTTP status codes for which empty responses are always valid.
[204, 205]by default.emptyRequestMethodsHTTPMethods for which empty responses are always valid.[.head]by default.optionsJSONSerialization.ReadingOptionsused when parsing the response..allowFragmentsby default.completionHandlerA closure to be executed once the request has finished.
Return Value
The request.
-
responseDecodable(of:queue: dataPreprocessor: decoder: emptyResponseCodes: emptyRequestMethods: completionHandler: ) Adds a handler using a
DecodableResponseSerializerto be called once the request has finished.Declaration
Swift
@discardableResult public func responseDecodable<T: Decodable>(of type: T.Type = T.self, queue: DispatchQueue = .main, dataPreprocessor: DataPreprocessor = DecodableResponseSerializer<T>.defaultDataPreprocessor, decoder: DataDecoder = JSONDecoder(), emptyResponseCodes: Set<Int> = DecodableResponseSerializer<T>.defaultEmptyResponseCodes, emptyRequestMethods: Set<HTTPMethod> = DecodableResponseSerializer<T>.defaultEmptyRequestMethods, completionHandler: @escaping (AFDataResponse<T>) -> Void) -> SelfParameters
typeDecodabletype to decode from response data.queueThe queue on which the completion handler is dispatched.
.mainby default.dataPreprocessorDataPreprocessorwhich processes the receivedDatabefore calling thecompletionHandler.PassthroughPreprocessor()by default.decoderDataDecoderto use to decode the response.JSONDecoder()by default.encodingThe 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.emptyResponseCodesHTTP status codes for which empty responses are always valid.
[204, 205]by default.emptyRequestMethodsHTTPMethods for which empty responses are always valid.[.head]by default.completionHandlerA closure to be executed once the request has finished.
Return Value
The request.
-
A closure used to validate a request that takes a URL request, a URL response and data, and returns whether the request was valid.
Declaration
Swift
public typealias Validation = (URLRequest?, HTTPURLResponse, Data?) -> ValidationResult -
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.
Declaration
Swift
@discardableResult public func validate<S>(statusCode acceptableStatusCodes: S) -> Self where S : Sequence, S.Element == IntParameters
acceptableStatusCodesSequenceof acceptable response status codes.Return Value
The instance.
-
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.
Declaration
Swift
@discardableResult public func validate<S>(contentType acceptableContentTypes: @autoclosure @escaping () -> S) -> Self where S : Sequence, S.Element == StringParameters
contentTypeThe acceptable content types, which may specify wildcard types and/or subtypes.
Return Value
The request.
-
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.
Declaration
Swift
@discardableResult public func validate() -> SelfReturn Value
The request.
View on GitHub
Install in Dash
DataRequest Class Reference