Last active
January 7, 2022 18:50
-
-
Save RealEmmettS/6653b772321215de7a5b117246dbe4ff 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
var api_result:[String]? | |
// The sample API request below is modeled off of the Gater API sample request. | |
// https://docs.gater.dev/the-basics/sending-and-receiving | |
// The default response to the sample API used below is | |
// {"main":{"status":"Gater is alive and well"}} | |
//MARK: API Request | |
func apiRequest(){ | |
let url = URL(string: ("https://api.gater.dev/status") )! | |
let task = URLSession.shared.dataTask(with: url) {(data, response, error) in | |
guard let data = data else { return } | |
let json = try? JSONSerialization.jsonObject(with: data, options: []) | |
//MARK: Parse API result | |
if let dictionary = json as? [String: Any] { | |
//print(dictionary) | |
if let rawResult = dictionary["main"]{ | |
//result is type __NSSingleEntryDictionaryI | |
guard let dictResult = rawResult as? [String:String] else {return} | |
print(dictResult["status"]!) | |
} | |
} | |
} | |
task.resume() | |
}//end of apiRequest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment