It is fully built with Protocol Oriented Programmig & Structs having dependency injection.
As its built fully in protocol oriented programming, you can override & add features very easily.
Right now FANetworkLayer is only supported via swift package manager. You can also install it manually. Incase you want it in other dependancy manager tools, please create an issue and I'll push it in them.
Get ready to get shock - As you'll see just couple of lines of code giving you everything you need :-)
Create your network manager class and conform it with APIRoutable
protocol so it can access features in FANetworkLayer
class MyNetworkManager: APIRoutable {
var sessionManager: APISessionManager = APISessionManager()
static let shared = MyNetworkManager()
private init() {}
}
Create your endpoints and conform it with URLDirectable
protocol so you can provide full urlString
for end points.
enum MyEndPoint: URLDirectable {
case allCountries
func urlString() -> String {
var endpoint = ""
switch (self) {
case .allCountries:
endpoint = "all"
}
return "https://restcountries.eu/rest/v2/" + endpoint
}
}
Use your newly created network manager by providing it API information as given in example below.
You can request three types of responses from server.
- Simple Request
- Request Object
- Request List
let api = API(method: .get, endPoint: MyEndPoint.allCountries, isAuthorized: false)
MyNetworkManager.shared.requestList(api, mapperType: Country.self, parsingLevel: "") { (result) in
switch result {
case .success(let value):
completion(value)
break
case .failure(let error):
failure(error)
break
}
}
Please check files under FANetworkLayer Usage Demo folder to understand how it's working.
If you want to override any of the features of APIRoutable
protocol, then just provide the implementation in your Network Manager
class as its conforming to this protocol.
If you want to add new functions then just add it in Network Manager
class as its conforming to APIRoutable
protocol.
FANetworkLayer is licensed under MIT.
For more details visit the LICENSE file for more info.
Fahid Attique - (https://github.com/fahidattique55)