Skip to content
JohnLui edited this page Oct 9, 2015 · 20 revisions

Basic use

You are recommended to use it manually.

Import

If you drag Pitaya project into your project, you may need to import it before use it:

import Pitaya

GET

Just give Google a hit:

Pitaya.request(.GET, url: "https://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