URLSession
extension URLSession
-
Executes a
RequestConvertible
request 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
request
A HTTP request to execute.
validateResponse
A block that validates the received response. This block can throw a custom error or return
false
to indicate an invalid response. If it returnsfalse
, the request will fail with aRequestError.unacceptableResponse
error. Default isnil
for no validation.decodingQueue
A
DispatchQueue
to decode the response body on. Default.global(.userInitiated)
.callbackQueue
A
DispatchQueue
to runcompletionHandler
on. Default.main
.configureTask
A block that receives the
URLSessionTask
for the request. This block will only be called if theRequestType
is successfully converted to aURLRequest
. You do not need to callresume()
on the provided task. The default implementation does nothing.completionHandler
A block executed when the request completes and the response body has been decoded.