FormsNetworking is a HTTP micro service
import FormsNetworking
FormsInjector.framework
FormsLogger.framework
FormsUtils.framework
Check if has internet connection
NetworkReachability.isConnected
Class should inheritance NetworkMethod class
class DemoNetworkMethod: NetworkMethod {
var url: URL! = "https://postman-echo.com/get?foo1=bar1&foo2=bar2".url
}
DemoNetworkMethod()
.call(
request,
onSuccess: { (_) in },
onError: { (_) in },
onCompletion: { (_, _) in })
class DemoNetworkMethod: NetworkMethod {
class Content: NetworkMethodContent {
var token: String?
var parameters: [String: Any]? {
var parameters: [String: Any?] = [:]
parameters["token"] = token
return parameters
}
var headers: [String: String?]? {
var headers: [String: String] = [:]
headers["language"] = "en"
return headers
}
}
var content: NetworkMethodContent?
var url: URL! = "https://postman-echo.com".url
var method: HTTPMethod = .POST
init(_ content: Content) {
self.content = content
}
}
class DemoNetworkMethod: NetworkMethod {
var url: URL! = "https://postman-echo.com".url
var requestInterceptor: NetworkRequestInterceptor? = AppNetworkRequestInterceptor()
}
class AppNetworkRequestInterceptor: NetworkRequestInterceptor {
override func setHeaders(_ request: Request) {
let headers = request.headers
/* set additional headers */
request.request.allHTTPHeaderFields = headers
}
}
class DemoNetworkMethod: NetworkMethod {
var url: URL! = "https://postman-echo.com".url
var responseInterceptor: NetworkResponseInterceptor? = AppNetworkResponseInterceptor()
}
class AppNetworkResponseInterceptor: NetworkResponseInterceptor {
override func postProcess(_ response: URLResponse?) {
}
}
class DemoNetworkMethod: NetworkMethod {
var url: URL! = "https://postman-echo.com".url
var parser: NetworkResponseParser? = AppNetworkResponseParser()
}
class AppNetworkResponseParser: NetworkResponseParser {
override func parseError(data: Data) -> NetworkError? {
// parse error from success response
return nil
}
}
DemoNetworkMethod()
.with(logger: VoidLogger())
.with(cache: NetworkTmpCache(ttl: 60 * 60))
.call(
request,
onSuccess: { (_) in },
onError: { (_) in },
onCompletion: { (_, _) in })
let request = DemoNetworkMethod()
.call(
request,
onSuccess: { (_) in },
onError: { (_) in },
onCompletion: { (_, _) in })
task.cancel()
NetworkPinning.isEnabled = true
NetworkPinning.certificates = [
Bundle.main.url(forResource: "certificate", withExtension: "cer")
].compactMap { $0 }