Skip to content

AndrexOfficial/NetX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NetX

Custom Network Manager using the latest Swift technology known as Async/Await, minimum compatible version: iOS 13.

Usage

Create a custom Client class and Routes enum:

Steps for Client creation

  1. the Client class should have its protocol with all the API functions exposed
  2. the class should extends its protocol
  3. the class should implement its own networkManager var or let private let networkManager: URLRequestProtocol which refers to URLRequestProtocol protocol (the one from NetX)
  4. perform a the class init by passing a custom networkManager or by using URLRequestClient.shared singleton from NetX
  5. each function will call the performURLRequest function declared from URLRequestProtocol protocol

Steps for Router creation

  1. the router enum must extend APIConfiguration protocol from NetX
  2. write all the case and pass the needed data as argument, e.g: case helloWorld(myName: String)
  3. the compiler will ask you to put all the missing vars and funcs declared and required by the APIConfiguration protocol
  4. if you want to create custom vars or to overwrite the existing ones, you just need to create an extension of APIConfiguration and then re-write the var or func you want to override

Client Example

import NetX

protocol FitmentFetchable {
    func getFitment(car: String) async throws -> FitmentModel
}

final class FitmentClient: FitmentFetchable {

private let networkManager: URLRequestProtocol

init(networkManager: URLRequestProtocol = URLRequestClient(requestClientConfigurator: RequestClientConfigurator(urlSession: .shared, needsLoader: true, needsRetry: true, retryLimit: 3, timeoutInterval: 30.0, cachePolicy: .useProtocolCachePolicy))) {
    self.networkManager = networkManager
}

func getFitment(car: String) async throws -> FitmentModel {
    try await networkManager.performURLRequest(FitmentRouter.getFitment(car: car), cacheId: nil)
    }
}

Router Example

import NetX

enum FitmentRouter: APIConfiguration {
    case getFitment(car: String)
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages