Here is your way for beginners (Swift, iOS developer)
Using cocoa framework in Swift
URLSession
Initialize a URL object and a URLSessionDataTask from URLSession. Then run the task with resume().
let url = URL(string: "http://www.stackoverflow.com")
let task = URLSession.shared.dataTask(with: url!) {(data, response, error) in
print(NSString(data: data!, encoding: String.Encoding.utf8))
}
task.resume()
NSURLConnection
First, initialize a URL and a URLRequest:
let url = URL(string: "http://www.stackoverflow.com")
let request = URLRequest(URL: url!)
Then, you can load the request asynchronously with:
NSURLConnection.sendAsynchronousRequest(request, queue:
NSOperationQueue.mainQueue()) {(response, data, error) in
print(NSString(data: data!, encoding: NSUTF8StringEncoding))
}
Using Alamofire - Awesome framework
https://github.com/Alamofire/Alamofire
Making a Request
import Alamofire
Alamofire.request(.GET, "http://httpbin.org/get")
Response Handling
Alamofire.request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"])
.response { request, response, data, error in
print(request)
print(response)
print(error)
}