WebService
Basic HTTP request classes in Swift
Install / Use
/learn @kansaraprateek/WebServiceREADME
WebService
[](https://travis-ci.org/Prateek Kansara/WebService)
Requirements
- iOS 8.0+
- Xcode 7.3.1+
Installation
WebService is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "WebService"
##Usage
// Import webService class
import WebService
// Basic Header Dictionary
var httpHeaderRequestDict : NSMutableDictionary!{
get{
let mutableDict : NSMutableDictionary = NSMutableDictionary()
mutableDict.setValue("AUTHKEY", forKey: "Authorization")
mutableDict.setValue("application/json", forKey: "Content-Type")
return mutableDict
}
}
// Create webService object
var webServiceObject : WebService = WebService()
// Set header value for all request
webServiceObject.setDefaultHeaders(httpHeaderRequestDict)
* use webServiceObject.httpHeaders to set different headers required for this call.
webServiceObject.sendRequest(URLString, parameters: params, requestType: .GET, success: {
(response : NSHTTPURLResponse?, dictionary : AnyObject) in
// Handle data when request Success
}, failed: {
(response : NSHTTPURLResponse?, ResponseDict : AnyObject?) in
// Handle data when request fails
}, encoded: false)
Example
To run the example project, clone the repo, and run pod install from the Example directory first.
Author
Prateek Kansara, prateek@kansara.in
License
WebService is available under the MIT license. See the LICENSE file for more info.
