GooseNet
This CocoaPods library is meant as a minimalistic async networking layer for reuse across projects to cut down on code repetition. Upcoming features include SSL-Pinning helpers for security concerns, request retrying, and webSocketTask and streamTask support.
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Usage
As shown in the Example app, the usage of the pod is as follows:
- Define a model that implements the Codable protocol for the data returned by your endpoint. In the case of the Example app:
public struct LegalDoc: Codable {
let url: String
}
- Define an implementation of the ServiceRequest protocol. The ResponseModel must be assigned your Codable model that represents the data returned by your endpoint. Iin the case of the Example app's GetLegalDoc service request:
import GooseNet
struct GetLegalDoc: ServiceRequest {
typealias ResponseModel = LegalDoc
var EndpointDefinition: Endpoint {
return Endpoint(baseUrl: "someTestBaseUrl.com", path: "/some/test/path")
}
- Call the Request method on the ServiceRequest implementation and handle the result. In the case of the Example app:
GetLegalDoc().Request { result in
switch result {
case .success(let legalDoc):
print("legal doc url: \(legalDoc.url)")
case .failure(let error):
print("request failure with error: \(error)")
}
}
Installation
GooseNet is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'GooseNet'
Author
Ali H. Shah, email: [email protected], linkedin
License
GooseNet is available under the MIT license. See the LICENSE file for more info.