Files
2021-06-03 17:59:25 +06:00

27 lines
778 B
Swift

//
// 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
}
}