RequestManager
public struct RequestManager : RequestableManager
Wrapper object that handles network session
-
Initializes the network session
Declaration
Swift
public init(session: URLSessionable = URLSession.shared)
Parameters
session
network session through which connection will be stablished with remote server. Defaults to Foundation
URLSession.shared
-
Triggers a generic request in an asynchronous matter
Example of usage:
let endpointRequest = URLRequest(url: URL(validURL: "github.com")) let sessionManager = RequestManager() sessionManager.request(endpointRequest) { result in switch(result) in case success(let response): // do whatever you wish with NetworkResult resulting type case failure(let errorType): // handle error appropriately }
Declaration
Swift
public func request(_ request: URLRequest, completion: @escaping NetworkResult)
Parameters
request
URL request specifications
completion
Resulting completion closure from request