- Booster was developed during NAVER Connect Foundation's the BoostCamp 3rd iOS Process.
- Booster is an Simple HTTP Networking Library written in Swift.
- Booster was created using only the Apple Frameworks.
- Basic REST API Call (GET, POST, PUT, DELETE)
- URL Query / Parameters Encoding
- Set HTTP Header Field
- throw CustomError
- Provide Examples
- Unit Test
- Multipart/Form-Data
- Refactoring
- Swift 4.2
- Xcode 10.0+
- iOS 12.0+
Booster officially supports CocoaPods only.
pod 'Booster'First, you should define an API Endpoint of type enum.
enumBoosterAPI{case fetchLiquidOxygen(type:String, quantity:Int)}Second, you should adopt the BoosterService protocol for an actual implementation of those requirements.
extensionBoosterAPI:BoosterService{varbaseURL:URL{guardlet url =URL(string:BaseURL.BoosterAPI)else{fatalError("Invalid URL")}return url
}varpath:String?{switchself{case.fetchLiquidOxygen:return"/fuel"}}varmethod:HTTPMethod{switchself{case.fetchLiquidOxygen:return.get
}}varparameters:Parameters{switchself{case.fetchLiquidOxygen(let type,let quantity):return["type": type,"quantity": quantity]}}vartask:HTTPTask{switchself{case.fetchLiquidOxygen:return.requestWith(url: parameters, body:nil, encoding:.query)}}varheader:HTTPHeader?{returnnil}}Third, you should implement BoosterManager(has Router) and define static method.
finalclassBoosterManager{staticfunc fetchLiquidOxygen(type:String, quantity:Int, completion:@escaping(Result<BoosterModel>)->Void){BoosterCenter<BoosterAPI>().request(.fetchLiquidOxygen(
type: type,
quantity: quantity
)){(data, error)inguard error ==nilelse{returncompletion(Result.failure(error!))}guardlet responseData = data else{return}do{letresultData=tryJSONDecoder().decode(BoosterModel.self, from: responseData)completion(Result.success(resultData))}catch{completion(Result.failure(BoosterError.decodingFail))}}}}Finally, you can access an API like this:
BoosterManager.fetchLiquidOxygen(type: type, quantity: quantity){ result inswitch result {case.success(let resultData):
// do something with response data
case .failure(let error):print(error.localizedDescription)}}Booster is released under an MIT license. See LICENSE.md for more information.
