Skip to content

michalkalinowski-/KituraRequest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KituraRequest

⚠️ Moved to Kitura organization ⚠️

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

Instalation

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.

Usage

API of KituraRequest should feel familiar as it closely maps the one of Alamofire.

Creating a request

To create a request object simply call

KituraRequest.request(method: .GET, "https://httpbin.org/get"]

Request parameters and parameters encoding

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.

Headers

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"])

Handling response

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
}

License

This library is licensed under Apache 2.0. For details see license.txt

About

Client request module for Kitura framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages