-
The request sent or to be sent to the server.
Declaration
Swift
open override var request: URLRequest? { get } -
The progress of fetching the response data from the server for the request.
Declaration
Swift
open var progress: Progress { get }
-
Sets a closure to be called periodically during the lifecycle of the request as data is read from the server.
This closure returns the bytes most recently received from the server, not including data from previous calls. If this closure is set, data will only be available within this closure, and will not be saved elsewhere. It is also important to note that the server data in any
Responseobject will benil.Declaration
Swift
@discardableResult open func stream(closure: ((Data) -> Void)? = nil) -> SelfParameters
closureThe code to be executed periodically during the lifecycle of the request.
Return Value
The request.
-
Sets a closure to be called periodically during the lifecycle of the
Requestas data is read from the server.Declaration
Swift
@discardableResult open func downloadProgress(queue: DispatchQueue = DispatchQueue.main, closure: @escaping ProgressHandler) -> SelfParameters
queueThe dispatch queue to execute the closure on.
closureThe code to be executed periodically as data is read from the server.
Return Value
The request.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func response(queue: DispatchQueue? = nil, completionHandler: @escaping (DefaultDataResponse) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
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<T: DataResponseSerializerProtocol>( queue: DispatchQueue? = nil, responseSerializer: T, completionHandler: @escaping (DataResponse<T.SerializedObject>) -> Void) -> SelfParameters
queueThe queue on which the completion handler is dispatched.
responseSerializerThe response serializer responsible for serializing the request, response, and data.
completionHandlerThe code to be executed once the request has finished.
Return Value
The request.
-
Creates a response serializer that returns the associated data as-is.
Declaration
Swift
public static func dataResponseSerializer() -> DataResponseSerializer<Data>Return Value
A data response serializer.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func responseData( queue: DispatchQueue? = nil, completionHandler: @escaping (DataResponse<Data>) -> Void) -> SelfParameters
completionHandlerThe code to be executed once the request has finished.
Return Value
The request.
-
Creates a response serializer that returns a result string type initialized from the response data with the specified string encoding.
Declaration
Swift
public static func stringResponseSerializer(encoding: String.Encoding? = nil) -> DataResponseSerializer<String>Parameters
encodingThe string encoding. If
nil, the string encoding will be determined from the server response, falling back to the default HTTP default character set, ISO-8859-1.Return Value
A string response serializer.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func responseString( queue: DispatchQueue? = nil, encoding: String.Encoding? = nil, completionHandler: @escaping (DataResponse<String>) -> Void) -> SelfParameters
encodingThe string encoding. If
nil, the string encoding will be determined from the server response, falling back to the default HTTP default character set, ISO-8859-1.completionHandlerA closure to be executed once the request has finished.
Return Value
The request.
-
Creates a response serializer that returns a JSON object result type constructed from the response data using
JSONSerializationwith the specified reading options.Declaration
Swift
public static func jsonResponseSerializer( options: JSONSerialization.ReadingOptions = .allowFragments) -> DataResponseSerializer<Any>Parameters
optionsThe JSON serialization reading options. Defaults to
.allowFragments.Return Value
A JSON object response serializer.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func responseJSON( queue: DispatchQueue? = nil, options: JSONSerialization.ReadingOptions = .allowFragments, completionHandler: @escaping (DataResponse<Any>) -> Void) -> SelfParameters
optionsThe JSON serialization reading options. Defaults to
.allowFragments.completionHandlerA closure to be executed once the request has finished.
Return Value
The request.
-
Creates a response serializer that returns an object constructed from the response data using
PropertyListSerializationwith the specified reading options.Declaration
Swift
public static func propertyListResponseSerializer( options: PropertyListSerialization.ReadOptions = []) -> DataResponseSerializer<Any>Parameters
optionsThe property list reading options. Defaults to
[].Return Value
A property list object response serializer.
-
Adds a handler to be called once the request has finished.
Declaration
Swift
@discardableResult public func responsePropertyList( queue: DispatchQueue? = nil, options: PropertyListSerialization.ReadOptions = [], completionHandler: @escaping (DataResponse<Any>) -> Void) -> SelfParameters
optionsThe property list reading options. Defaults to
[].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 the request, using the specified closure.
If validation fails, subsequent calls to response handlers will have an associated error.
Declaration
Swift
@discardableResult public func validate(_ validation: @escaping Validation) -> SelfParameters
validationA closure to validate the request.
Return Value
The request.
-
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: 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