- iOS 13 and above
Import dependenices:
import Combine
import EZANetwork
- Inherit EZARequest protocol and define required fields:
enum NetworkApi {
case login(requestObject: Encodable)
}
extension NetworkApi: EZARequest {
var url: URL {
switch self {
case .login: return "some url"
}
}
var path: String? {
switch self {
case .login: return "api/login"
}
}
var method: HTTPMethod {
switch self {
case .login: return .get
}
}
var task: EZATask {
switch self {
case .login(let requestObject):
let params = try? requestObject.asDictionary()
return .query(parameters: params ?? [:])
}
}
}
- Call api endpoint using publisher:
var cancellables: Set<AnyCancellable> = .init()
NetworkApi
.login(requestObject: ["username": "user", "password": "pass"])
.request()
.sink { completion in
<#code#>
} receiveValue: { value in
<#code#>
}
.store(in: &cancellables)
- You can also set logging level for EZANetwork
EZALogger.set(logLevel: .error) // .debug by default. Set ".disabled" to disable all logs
EZANetwork is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'EZANetwork'
- Right click in the Project Navigator
- Select "Add Packages..."
- Search for
https://github.com/eugene-software/EZANetwork.git
Eugene Software
EZANetwork is available under the MIT license. See the LICENSE file for more info.