https://github.com/IBM-Swift/Kitura-Request
A module for sending HTTP requests in IBM Kitura based applications. It wraps KituraNet ClientRequest
class and exposes a familiar interface known from Alamofire.
TODO:
- !! Add URL parameter encoding
- !! Add JSON parameter encoding
- !! Make tests run on Linux
- !! Write tests to check if resulting ClientRequest is properly initialised
- Add synchronus interface
- Add async interface
- Write instructions
- Switch back to depend on IBM Kitura-net
To install KituraRequest add following line to Dependencies in Package.json
:
.Package(url: "https://github.com/michalkalinowski-/KituraRequest.git", majorVersion: 0)
Currently DEVELOPMENT-SNAPSHOT-2016-05-03-a
toolchain is supported, support for Swift 3.0 will happen as soon as KituraNet migrates.
API of KituraRequest should feel familiar as it closely maps the one of Alamofire.
To create a request object simply call
KituraRequest.request(method: .GET, "https://httpbin.org/get"]
You can also create a request with parameters by passing [String: AnyObject]
dictionary together with encoding method
KituraRequest.request(method: .POST,
"https://httpbin.org/post",
parameters: ["foo":"bar"],
encoding: .JSON)
Currently .URL
and .JSON
encoding is supported. .URL
encodes parameters as URLs query while the latter converts parameters dictionary to JSON and appends it to request's body. When encoding parameters as .JSON
appropriate Content-Type header is set.
To set headers in the request pass them as [String: String]
dictionary as shown below:
KituraRequest.request(method: .GET,
"https://httpbin.org/get",
headers: ["User-Agent":"Awesome-App"])
Currently there is only one method that you can call to get back the requests response and it returns NSData
.
KituraRequest.request(method: .GET, "https://google.com"].response {
request, response, data, error in
// do something with data
}
This library is licensed under Apache 2.0. For details see license.txt