TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Apr 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Patrick Montalto.
Provides a lightweight and simple NetworkClient to build and intiate URLRequests in Swift.
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate SwiftNetworking into your Xcode project using Cocoapods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!
target '<Your Target Name>' do
pod 'SwiftNetworking'
end
Then, run the following command:
$ pod install
Initialize a NetworkClient object with a baseURL. You may also include a custom session (defaults to URLSession.shared).
import SwiftNetworking
let baseURL = URL(string: "http://example.com/api/v1")!
let client = NetworkClient(baseURL: baseURL)
let request = client.buildRequest(method: .get, path: "me")
let client = NetworkClient(baseURL: baseURL)
client.request(path: "me")
You may also provide a completion handler. An enum Result<Element>
serves to contain the success and failure cases of a network request response. The completion handler is of type (NetworkResult) -> Void
, where NetworkResult
is a typealias
of Result<(URLResponse, Data?)>
.
client.request(path: "me") { (result) in
switch result {
case .success(let response, let data):
// Handle success
case .failure(let error):
// Handle failure
}
}
SwiftNetworking is available under the MIT license. See the LICENSE file for more info.