Created
November 12, 2021 08:32
-
-
Save dimkagithub/c6f14a9ea541a3395b082730bcdcd59c to your computer and use it in GitHub Desktop.
URLSession
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
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