-
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.
-
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 responseData(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 responseString(queue: DispatchQueue = .main, encoding: String.Encoding? = nil, completionHandler: @escaping (AFDataResponse<String>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby 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.completionHandlerA closure 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 responseJSON(queue: DispatchQueue = .main, options: JSONSerialization.ReadingOptions = .allowFragments, completionHandler: @escaping (AFDataResponse<Any>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
.mainby default.optionsThe JSON serialization reading options.
.allowFragmentsby default.completionHandlerA closure 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 responseDecodable<T: Decodable>(of type: T.Type = T.self, queue: DispatchQueue = .main, decoder: DataDecoder = JSONDecoder(), completionHandler: @escaping (AFDataResponse<T>) -> Void) -> SelfParameters
typeDecodabletype to decode from response data.queueThe queue on which the completion handler is dispatched.
.mainby default.decoderDataDecoderto use to decode the response.JSONDecoder()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
rangeThe range of acceptable status codes.
Return Value
The request.
-
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