Swiftpack.co - Package - nghiadev95/RequestKits

Build Status Cocoapods platforms Cocoapods SPM compatible Swift Xcode MIT

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

Requirements

  • iOS 11.0+
  • Swift 5.0+

Dependency

  • RxSwift
  • Alamofire

Installation

CocoaPods

To integrate RequestKits into your Xcode project using CocoaPods, specify it in your Podfile

pod 'RequestKits'

Swift Package Manager

You can use The Swift Package Manager to install RequestKits by adding the proper description to your Package.swift

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .package(url: "https://github.com/nghiadev95/RequestKits.git", from: "1.0.0")
    ]
)

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)

Operation Queue

  • Request Queue Manager
RequestManager.instance.updateMaxConcurrentOperationCount(2)
RequestManager.instance.updateQualityOfService(.background)

DownloadManager.instance.updateMaxConcurrentOperationCount(2)
DownloadManager.instance.updateQualityOfService(.background)

UploadManager.instance.updateMaxConcurrentOperationCount(2)
UploadManager.instance.updateQualityOfService(.background)

Pluggin

  • RequestAdapter

-- Authentication

public enum Authentication {
    case bearer(token: String)
    case basic(token: String)
    case credential(username: String, password: String)
    case custom(name: String, token: String)
}
  • EventMonitor

--NetworkLogger

public struct NetworkLogger: EventMonitor {
    public enum Level: String {
        case verbose
        case debug
        case info
    }
}

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.

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

Alpha - 2020-08-23 06:45:34