Created
November 9, 2019 17:28
-
-
Save wadheraswati/b2bc650feb822749b3b0a85ad11ca4ea to your computer and use it in GitHub Desktop.
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
func getURLRequest(method: HTTPMethod, body: Encodable? = nil, params: [String: Any]? = nil) throws -> URLRequest { | |
do { | |
var queryParams = [String: Any]() | |
if let myParams = params { | |
queryParams = myParams | |
} | |
let myURL = try urlString.asURL() | |
var urlRequest = URLRequest(url: myURL) | |
urlRequest.httpMethod = method.rawValue | |
if let apiBody = body { | |
let encodedURLRequest = try URLEncoding.default.encode(urlRequest, with: apiBody.asJson()) | |
return encodedURLRequest | |
} | |
return urlRequest | |
} catch { | |
// handle the exception here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment