Skip to content

RequestKits is a framework for network request (API Request, Upload/Download Task)

License

Notifications You must be signed in to change notification settings

quangnghiadev/RequestKits

Repository files navigation

Build Status SPM compatible Swift Xcode MIT

RequestKits

RequestKits is a framework for network request (API Request, Upload/Download Task)

Requirements

  • iOS 11.0+
  • Swift 5.0+

Dependency

  • RxSwift
  • Alamofire

Installation

Swift Package Manager

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

Usage

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)

Pluggin

RequestAdapter

EventMonitor

License

  • RequestKits is using Alamofire. See LICENSE for more information.
  • RequestKits is using RxSwift. See LICENSE for more information.
  • RequestKits is using source code from Moya. See LICENSE for more information.
  • RequestKits is released under the MIT license. See LICENSE for more information.