项目作者: SanjithKanagavel

项目描述 :
iOS Networking library using RxSwift
高级语言: Swift
项目地址: git://github.com/SanjithKanagavel/RxNetworking.git
创建时间: 2020-11-18T19:10:11Z
项目社区:https://github.com/SanjithKanagavel/RxNetworking

开源协议:MIT License

下载


RxNetworking

Networking library using RxSwift

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

RxNetworking is available through CocoaPods. To install
it, simply add the following line to your Podfile:

  1. pod 'RxNetworking'

Usage

DataTask with URL :

  1. if let url = URL(string: "<url>") {
  2. URLSession.shared
  3. .rx
  4. .dataTask(url: url)
  5. .subscribe(onNext: { (result) in
  6. if result.Error == nil, let data = result.Data {
  7. print("urlDataTaskExample:\n" + String(decoding: data, as: UTF8.self))
  8. }
  9. }).disposed(by: disposeBag)
  10. }

DataTask with URLRequest :

  1. var request = URLRequest(url: URL(string: "<url>")!,timeoutInterval: Double.infinity)
  2. request.httpMethod = "GET"
  3. URLSession.shared
  4. .rx
  5. .dataTask(request: request)
  6. .subscribe(onNext: { (result) in
  7. if result.Error == nil, let data = result.Data {
  8. print("getRequest:\n" + String(decoding: data, as: UTF8.self))
  9. }
  10. }).disposed(by: disposeBag)

Inbuilt decode with dataTask :

  1. if let url = URL(string: "<url>") {
  2. URLSession.shared
  3. .rx
  4. .dataTask(url: url,returnType: YourCodableStruct.self)
  5. .subscribe(onNext: { (result) in
  6. if result.Error == nil, let data = result.Data,
  7. let jsonData = try? JSONEncoder().encode(data),
  8. let jsonString = String(data: jsonData, encoding: .utf8) {
  9. print(jsonString)
  10. }
  11. }).disposed(by: disposeBag)
  12. }

returnType should extend Codable Protocol

downloadTask, uploadTask methods are added for download and uploading files

Requirements

  • iOS 9.0+
  • Xcode 7.0+

Author

SanjithKanagavel, sanjithkanagavel@gmail.com

License

RxNetworking is available under the MIT license. See the LICENSE file for more info.