Created
June 18, 2020 14:12
-
-
Save stevencurtis/588bec50335625eb9bca18e1aea7416b to your computer and use it in GitHub Desktop.
APIRouter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol APIRouter: URLRequestConvertible { | |
var method: HTTPMethod { get } | |
var path: String { get } | |
var actionParameters: [String: Any] { get } | |
var baseURL: String { get } | |
var authHeader: HTTPHeaders? { get } | |
var encoding: ParameterEncoding { get } | |
} | |
extension APIRouter { | |
func asURLRequest() throws -> URLRequest { | |
let originalRequest = try URLRequest( | |
url: baseURL.appending(path), | |
method: method, | |
headers: authHeader) | |
let encodedRequest = try encoding.encode( | |
originalRequest, | |
with: actionParameters) | |
return encodedRequest | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment