Protocol oriented iOS Networking Framework for common tasks written in swift
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate FlexyNetwork into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'FlexyNetwork'
For example, let's consider following image request:
struct ExampleRequest: HTTPGETRequest {
var parameters: JSON?
var headerFields: [String : String]?
var path: String {
return "https://avatars.mds.yandex.net/get-pdb/51720/e8b9e4c0-18e8-41d9-97e2-806660d42973/s1200"
}
}
public protocol FlexDecodable {
static var jsonDecoder: JSONDecoder? { get }
static func decodeFrom(_ data: Data) throws -> Self
}
Swift Decodable
protocol, UIImage
, String
, Dictionary
and Array
are already extended to confirm to the protocol. However, if you want to change jsonDecoder for your model, you can implement the property in your model. Or you can define protocol like this:
protocol SnakeCaseDecodable: FlexDecodable {}
extension SnakeCaseDecodable {
static var jsonDecoder: JSONDecoder? {
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = .convertFromSnakeCase
return decoder
}
}
As our example is about image request, so there is nothing to do.
FlexNetService
using APIBuilder
and handle responseAPIBuilder()
.setRequest(ExampleRequest())
.build(for: UIImage.self, orError: FlexNever.self)
.sendRequest()?.onSuccess({ (image) in
print(image)
})
APIBuilder
builds service from objects that implement:
Logger
- protocol for logging request and responseHeadersHandler
- protocol for handling headers from responseRequestPreparator
- protocol for preparing request before sending itNestedModelGetter
- protocol that allows you to get nested data from responseSuccessResponseChecker
- protocol for defining whether reposnse is successful or notSSLPinningKeysProvider
- closure that provides keys to implement SSL pinning against specific hostHTTPRequestRepresentable
FlexNetService
supports numerous callbacks:
SuccessResponseChecker
implementationSuccessResponseChecker
implementationPagedRequest
and there is no pages leftlink |
Stars: 0 |
Last commit: 21 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics