Skip to content

Instantly share code, notes, and snippets.

@farhan-syed
Last active June 10, 2018 00:30
Show Gist options
  • Save farhan-syed/5732f875d7059c71cc1d0676641b79e9 to your computer and use it in GitHub Desktop.
Save farhan-syed/5732f875d7059c71cc1d0676641b79e9 to your computer and use it in GitHub Desktop.
func fetchPosts(){
Alamofire.request("https://jsonplaceholder.typicode.com/posts", method: .get, parameters: nil)
.validate(statusCode: 200..<300).responseJSON { response in
guard response.result.error == nil else {
print("error calliing on /posts")
return
}
guard let json = response.result.value as? [String:Any] else {
print("didn't get any json objects from API")
return
}
print(json)
}
}
func fetchComments(){
Alamofire.request("https://jsonplaceholder.typicode.com/comments", method: .get, parameters: nil)
.validate(statusCode: 200..<300).responseJSON { response in
guard response.result.error == nil else {
print("error calliing POST on /comments")
return
}
guard let json = response.result.value as? [String:Any] else {
print("didn't get any json objects from API")
return
}
print(json)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment