URLSession
extension URLSession
-
Executes a
RequestConvertiblerequest and attempts to decode the response body.Declaration
Swift
public func perform<R: RequestConvertible>( _ request: R, validateResponse validationBlock: ((HTTPURLResponse) throws -> Bool)? = nil, decodingQueue: DispatchQueue = .global(qos: .userInitiated), callbackQueue: DispatchQueue = .main, configureTask: (URLSessionTask) -> Void = { _ in }, completionHandler: @escaping (NetworkResult<R.Resource>) -> Void )Parameters
requestA HTTP request to execute.
validateResponseA block that validates the received response. This block can throw a custom error or return
falseto indicate an invalid response. If it returnsfalse, the request will fail with aRequestError.unacceptableResponseerror. Default isnilfor no validation.decodingQueueA
DispatchQueueto decode the response body on. Default.global(.userInitiated).callbackQueueA
DispatchQueueto runcompletionHandleron. Default.main.configureTaskA block that receives the
URLSessionTaskfor the request. This block will only be called if theRequestTypeis successfully converted to aURLRequest. You do not need to callresume()on the provided task. The default implementation does nothing.completionHandlerA block executed when the request completes and the response body has been decoded.
View on GitHub
URLSession Extension Reference