-
Notifications
You must be signed in to change notification settings - Fork 1
DataRequest
Request
subclass which handles in-memory Data
download using URLSessionDataTask
.
public class DataRequest: 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.
public typealias Validation = (URLRequest?, HTTPURLResponse, Data?) -> ValidationResult
URLRequestConvertible
value used to create URLRequest
s for this instance.
let convertible: URLRequestConvertible
Data
read from the server so far.
var data: Data?
Validates the request, using the specified closure.
@discardableResult public func validate(_ validation: @escaping Validation) -> Self
- validation:
Validation
closure used to validate the response.
The instance.
Adds a handler to be called once the request has finished.
@discardableResult public func response(queue: DispatchQueue = .main, completionHandler: @escaping (AFDataResponse<Data?>) -> 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.
Adds a handler to be called once the request has finished.
@discardableResult public func response<Serializer: DataResponseSerializerProtocol>(queue: DispatchQueue = .main, responseSerializer: Serializer, completionHandler: @escaping (AFDataResponse<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.
- completionHandler: The code to be executed once the request has finished.
The request.
Adds a handler to be called once the request has finished.
@discardableResult public func responseData(queue: DispatchQueue = .main, completionHandler: @escaping (AFDataResponse<Data>) -> 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.
Adds a handler to be called once the request has finished.
@discardableResult public func responseString(queue: DispatchQueue = .main, encoding: String.Encoding? = nil, completionHandler: @escaping (AFDataResponse<String>) -> Void) -> Self
- queue: The queue on which the completion handler is dispatched.
.main
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
. - completionHandler: A closure to be executed once the request has finished.
The request.
Adds a handler to be called once the request has finished.
@discardableResult public func responseJSON(queue: DispatchQueue = .main, options: JSONSerialization.ReadingOptions = .allowFragments, completionHandler: @escaping (AFDataResponse<Any>) -> Void) -> Self
- queue: The queue on which the completion handler is dispatched.
.main
by default. - options: The JSON serialization reading options.
.allowFragments
by default. - completionHandler: A closure to be executed once the request has finished.
The request.
Adds a handler to be called once the request has finished.
@discardableResult public func responseDecodable<T: Decodable>(of type: T.Type = T.self, queue: DispatchQueue = .main, decoder: DataDecoder = JSONDecoder(), completionHandler: @escaping (AFDataResponse<T>) -> Void) -> Self
- type:
Decodable
type to decode from response data. - queue: The queue on which the completion handler is dispatched.
.main
by default. - decoder:
DataDecoder
to use to decode the response.JSONDecoder()
by default. - completionHandler: A closure to be executed once the request has finished.
The request.
Validates that the response has a status code in the specified sequence.
@discardableResult public func validate<S: Sequence>(statusCode acceptableStatusCodes: S) -> Self where S.Iterator.Element == Int
If validation fails, subsequent calls to response handlers will have an associated error.
- range: The range of acceptable status codes.
The request.
Validates that the response has a content type in the specified sequence.
@discardableResult public func validate<S: Sequence>(contentType acceptableContentTypes: @escaping @autoclosure () -> S) -> Self where S.Iterator.Element == String
If validation fails, subsequent calls to response handlers will have an associated error.
- contentType: The acceptable content types, which may specify wildcard types and/or subtypes.
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.
@discardableResult public func validate() -> Self
If validation fails, subsequent calls to response handlers will have an associated error.
The request.
Generated at 2020-09-24T22:11:06+0000 using swift-doc 1.0.0-beta.4.
Types
- AF
- AFError
- AFError.MultipartEncodingFailureReason
- AFError.ParameterEncoderFailureReason
- AFError.ParameterEncoderFailureReason.RequiredComponent
- AFError.ParameterEncodingFailureReason
- AFError.ResponseSerializationFailureReason
- AFError.ResponseValidationFailureReason
- AFError.ServerTrustFailureReason
- AFError.ServerTrustFailureReason.Output
- AFError.URLRequestValidationFailureReason
- Adapter
- AlamofireExtension
- AlamofireNotifications
- ClosureEventMonitor
- CompositeEventMonitor
- CompositeTrustEvaluator
- ConnectionLostRetryPolicy
- DataRequest
- DataResponse
- DataResponseSerializer
- DecodableResponseSerializer
- DefaultTrustEvaluator
- DisabledEvaluator
- DownloadRequest
- DownloadRequest.Downloadable
- DownloadRequest.Options
- DownloadResponse
- Empty
- GoogleXSSIPreprocessor
- HTTPHeader
- HTTPHeaders
- HTTPMethod
- Interceptor
- JSONEncoding
- JSONParameterEncoder
- JSONResponseSerializer
- MultipartFormData
- NetworkReachabilityManager
- NetworkReachabilityManager.NetworkReachabilityStatus
- NetworkReachabilityManager.NetworkReachabilityStatus.ConnectionType
- PassthroughPreprocessor
- PinnedCertificatesTrustEvaluator
- PublicKeysTrustEvaluator
- Redirector
- Redirector.Behavior
- Request
- Request.State
- ResponseCacher
- ResponseCacher.Behavior
- Retrier
- RetryPolicy
- RetryResult
- RevocationTrustEvaluator
- RevocationTrustEvaluator.Options
- ServerTrustManager
- Session
- SessionDelegate
- StringResponseSerializer
- URLEncodedFormEncoder
- URLEncodedFormEncoder.ArrayEncoding
- URLEncodedFormEncoder.BoolEncoding
- URLEncodedFormEncoder.DataEncoding
- URLEncodedFormEncoder.DateEncoding
- URLEncodedFormEncoder.Error
- URLEncodedFormEncoder.KeyEncoding
- URLEncodedFormEncoder.SpaceEncoding
- URLEncodedFormParameterEncoder
- URLEncodedFormParameterEncoder.Destination
- URLEncoding
- URLEncoding.ArrayEncoding
- URLEncoding.BoolEncoding
- URLEncoding.Destination
- UploadRequest
- UploadRequest.Uploadable
Protocols
- AlamofireExtended
- CachedResponseHandler
- DataDecoder
- DataPreprocessor
- DataResponseSerializerProtocol
- DownloadResponseSerializerProtocol
- EmptyResponse
- EventMonitor
- ParameterEncoder
- ParameterEncoding
- RedirectHandler
- RequestAdapter
- RequestDelegate
- RequestInterceptor
- RequestRetrier
- ResponseSerializer
- ServerTrustEvaluating
- URLConvertible
- URLRequestConvertible
- UploadConvertible
- UploadableConvertible