ModifyRequestNetworkService
public final class ModifyRequestNetworkService : NetworkService
                ModifyRequestNetworkService can be composed with a network service to modify all outgoing requests.
One could add auth tokens or API keys for specifics URLs.
Example:
let networkService: NetworkService = //
let modifyRequestNetworkService = ModifyRequestNetworkService(networkService: networkService, requestModifications: [ { request in
   return request.added(HTTPHeaderFields: ["API-Key": "SecretKey"])
}])
Note
Requests can only be modified syncronously.Seealso
NetworkService
- 
                  
                  
Creates an insatcne of
ModifyRequestNetworkService.Declaration
Swift
public init(networkService: NetworkService, requestModifications: [(URLRequest) -> URLRequest])Parameters
networkServicea networkservice.
requestModificationsarray of modifications to modify requests.
 - 
                  
                  
Fetches a resource asynchronously from remote location. Execution of the requests starts immediately. Execution happens on no specific queue. It dependes on the network access which queue is used. Once execution is finished either the completion block or the error block gets called. You decide on which queue these blocks get executed.
Example:
let networkService: NetworkService = // let resource: Resource<String> = // networkService.request(queue: .main, resource: resource, onCompletionWithResponse: { htmlText, response in print(htmlText, response) }, onError: { error in // Handle errors })Declaration
Swift
@discardableResult public func request<Result>(queue: DispatchQueue, resource: Resource<Result>, onCompletionWithResponse: @escaping (Result, HTTPURLResponse) -> Void, onError: @escaping (NetworkError) -> Void) -> NetworkTaskParameters
queueThe
DispatchQueueto execute the completion and error block on.resourceThe resource you want to fetch.
onCompletionWithResponseCallback which gets called when fetching and transforming into model succeeds.
onErrorCallback which gets called when fetching or transforming fails.
Return Value
a running network task
 
View on GitHub
        ModifyRequestNetworkService Class Reference