Skip to content
JohnLui edited this page Aug 28, 2015 · 20 revisions

##Basic use

You are recommended to use it manually.

###GET

Just give Google a hit:

Pitaya.request(.GET, url: "http://www.google.com", errorCallback: nil, callback: nil)

###GET with callback

Pitaya.request(.GET, url: "http://httpbin.org/get", errorCallback: nil) { (data, response) -> Void in
    print("Got it!")
}

###GET the String

Pitaya.request(.GET, url: "http://httpbin.org/get", errorCallback: nil) { (data, response) -> Void in
    let string = NSString(data: data!, encoding: NSUTF8StringEncoding) as! String
    print(string)
}

###GET all http headers

Pitaya.request(.GET, url: "http://httpbin.org/get", errorCallback: nil) { (data, response) -> Void in
    for (i,j) in response!.allHeaderFields {
        print("\(i): \(j)")
    }
}
Clone this wiki locally