I've got this function to fetch a JSON API, but I need to set custom parameters.
Here is the function:
func fetchTipsJson(completion: @escaping (Result<Root, Error>) -> ()) {
let urlString = "http://telemedapi_dev.assistcard.com/Api/Config/GetConfigGroupList"
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url) { (data, resp, err) in
// Error
if let err = err {
completion(.failure(err))
return
}
// Successful
do {
let tips = try JSONDecoder().decode(Root.self, from: data!)
completion(.success(tips))
print(tips)
} catch let jsonError {
completion(.failure(jsonError))
}
}.resume()
}
And here are the parameters:
{
"Parameters": {
"CountryCode": 540,
"ConfigurationPath": "TelemedGlobalConfig>Tips",
"LogApiCallsStatus": 2
},
"VisitorIp": null,
"ApplicationName": null,
"CurrentUICulture": "es-ES"
}
How can I do this? I can't find anything. Notice that I'm using the new Result
from Swift 5, don't know if that changes anything.