Skip to content

Instantly share code, notes, and snippets.

@dimkagithub
Created November 12, 2021 08:32
Show Gist options
  • Save dimkagithub/c6f14a9ea541a3395b082730bcdcd59c to your computer and use it in GitHub Desktop.
Save dimkagithub/c6f14a9ea541a3395b082730bcdcd59c to your computer and use it in GitHub Desktop.
URLSession
let headers = [
"x-rapidapi-host": "covid-19-data.p.rapidapi.com",
"x-rapidapi-key": "177e0ab6e3msh242bbbb79f55e0fp161398jsna8fc21704db9"
]
let request = NSMutableURLRequest(url: NSURL(
string: "https://covid-19-data.p.rapidapi.com/country/all")! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse)
}
})
dataTask.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment