// // URLParameterEncoder.swift // Cyberlock // // Created by Jura on 8/21/19. // Copyright © 2019 Omicronmedia. All rights reserved. // import Foundation public struct URLParameterEncoder: ParameterEncoder { public static func encode(parameters: HTTPParameters, for request: inout URLRequest) throws { guard let url = request.url , var urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) else { throw NetworkRouterError.invalidUrl } urlComponents.queryItems = parameters.map { URLQueryItem(name: $0.key, value: "\($0.value)".addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)) } request.url = urlComponents.url } }