RequestKits is a framework for network request (API Request, Upload/Download Task)
- iOS 11.0+
- Swift 5.0+
- RxSwift
- Alamofire
You can use The Swift Package Manager to install RequestKits by adding https://github.com/quangnghiadev/RequestKits.git to Swift Package of your XCode project
Define your Network instance
private let network = Network(config: NetworkConfig())
Make a request with:
- Pure
var request = URLRequest(url: URL(string: "https://httpbin.org/get")!)
request.method = .get
network.request(request, validationType: .successCodes) { data, error in
print(data as Any)
print(error as Any)
}
- Requestable
struct GetAllPostsRequest: Requestable {
var baseURL: URL {
return URL(string: "https://httpbin.org/")!
}
var path: String {
return "get"
}
var method: HTTPMethod {
return .get
}
var task: Task {
.requestPlain
}
}
network.request(requestable: GetAllPostsRequest()) { data, error in
print(data as Any)
print(error as Any)
}
- RxSwift and Requestable
let request: Observable<EmptyEntity> = network.rxRequest(requestable: GetAllPostsRequest())
request.subscribe(onNext: { response in
print(response)
}).disposed(by: disposeBag)