A Short Example call Rest Api with JSON Foundation framework NSURLSession and NSJSONSerialization -
Getting Started - Basic Rest API request with Swift 4
func restApiRequest(){
let sessionConfig = URLSessionConfiguration.default
// Session Configuration
let sessionUrl = URLSession(configuration: sessionConfig)
// Load configuration into Session
let url = URL(string: "YOUR URL STRING")!
let task = sessionUrl.dataTask(with: url, completionHandler: {
(data, response, error) in
if error != nil {
print(error!.localizedDescription)
} else {
do {
if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any]
{
print(json)
}
} catch {
print("error in JSONSerialization")
}
}})
task.resume()
}
AMZ Researcher - FBA revenue calculation
Getting Started - Basic Rest API request with Swift 4
func restApiRequest(){
let sessionConfig = URLSessionConfiguration.default
// Session Configuration
let sessionUrl = URLSession(configuration: sessionConfig)
// Load configuration into Session
let url = URL(string: "YOUR URL STRING")!
let task = sessionUrl.dataTask(with: url, completionHandler: {
(data, response, error) in
if error != nil {
print(error!.localizedDescription)
} else {
do {
if let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any]
{
print(json)
}
} catch {
print("error in JSONSerialization")
}
}})
task.resume()
}

AMZ Researcher - FBA revenue calculation
Comments
Post a Comment