RxNetworks

0.4.5

๐Ÿงš MVP Network Api library. ๆ’ไปถ็‰ˆ็ฝ‘็ปœๅŸบ็ก€ๆžถๆž„๏ผŒๆ”ฏๆŒๅ“ๅบ”ๅผใ€‚
yangKJ/RxNetworks

What's New

Networking

2023-11-11T07:00:42Z

Add shared plugin and files plugin.

RxNetworks

Carthage compatible Releases Compatible CocoaPods Compatible Platform

RxNetworks is a declarative and reactive networking library for Swift. Developed for Swift 5, it aims to make use of the latest language features. The framework's ultimate goal is to enable easy networking that makes it easy to write well-maintainable code.

๐Ÿงš. RxSwift + Moya + HandyJSON + Plugins.๐Ÿ‘’๐Ÿ‘’๐Ÿ‘’


English | ็ฎ€ไฝ“ไธญๆ–‡

This is a network api set of infrastructure based on Moya, also support responsive network with RxSwift.

Features

At the moment, the most important features of RxNetworks can be summarized as follows:

  • Support reactive network requests combined with RxSwift.
  • Support for OOP also support POP network requests.
  • Support data parsing with HandyJSON.
  • Support configuration of general request and path, general parameters, etc.
  • Support simple customization of various network plugins for Moya.
  • Support uploading and downloading files/resources and so on.
  • Support for injecting default plugins with NetworkConfig.basePlugins.
  • Support 10 plugins have been packaged for you to use.

Usages

How to use USAGE.

SharedAPI.loading("Condy").HTTPRequest(success: { _ in
    // do somthing..
}, failure: { _ in
    
})

Plugins

This module is mainly based on moya package network related plugins.

  • At present, 10 plugins have been packaged for you to use:
    • HTTPHeader: Network HTTP Header Plugin.
    • Cache: Network Data Cache Plugin.
    • Loading: Load animation plugin.
    • Indicator: Indicator plugin.
    • Warning: Network failure prompt plugin.
    • Debugging: Network printing, built in plugin.
    • GZip: Network data unzip plugin.
    • Shared: Network sharing plugin.
    • AnimatedLoading: Animation loading plugin based on lottie.
    • Files: Network Downloading Files And Uploading Resources Plugin.

๐Ÿ  Simple to use, implement the protocol method in the API protocol, and then add the plugin to it:

var plugins: APIPlugins {
    let cache = NetworkCachePlugin.init(options: .cacheThenNetwork)
    let loading = NetworkLoadingPlugin.init(options: .init(delay: 0.5))
    let warning = NetworkWarningPlugin.init()
    let shared = NetworkSharedPlugin.init()
    let gzip = NetworkGZipPlugin.init()
    return [loading, cache, warning, shared, gzip]
}

RxSwift

This module mainly supports responsive data binding.

func request(_ count: Int) -> Observable<[CacheModel]> {
    CacheAPI.cache(count).request()
        .mapHandyJSON(HandyDataModel<[CacheModel]>.self)
        .compactMap { $0.data }
        .observe(on: MainScheduler.instance)
        .catchAndReturn([])
}

HandyJSON

This module is based on HandyJSON package network data parsing.

  • Roughly divided into the following 3 parts:
    • HandyDataModel: Network outer data model.
    • HandyJSONError: Parse error related.
    • RxHandyJSON: HandyJSON data parsing, currently provides two parsing solutions.
      • Option 1: Combine HandyDataModel model to parse out data.
      • Option 2: Parse the data of the specified key according to keyPath, the precondition is that the json data source must be in the form of a dictionary.

๐ŸŽท Example of use in conjunction with the network part:

func request(_ count: Int) -> Driver<[CacheModel]> {
    CacheAPI.cache(count).request()
        .asObservable()
        .mapHandyJSON(HandyDataModel<[CacheModel]>.self)
        .compactMap { $0.data }
        .observe(on: MainScheduler.instance)
        .delay(.seconds(1), scheduler: MainScheduler.instance)
        .asDriver(onErrorJustReturn: [])
}

CocoaPods

CocoaPods is a dependency manager. For usage and installation instructions, visit their website. To integrate using CocoaPods, specify it in your Podfile:

pod 'RxNetworks'

You should define your minimum deployment target explicitly, like:

platform :ios, '10.0'

If you only want import cache plugin:

pod 'RxNetworks/Plugins/Cache'

For other plugins and modules excluded, please read the podspec file.

Remarks

The general process is almost like this, the Demo is also written in great detail, you can check it out for yourself.๐ŸŽท

RxNetworksDemo

Tip: If you find it helpful, please help me with a star. If you have any questions or needs, you can also issue.

Thanks.๐ŸŽ‡

About the author

Buy me a coffee or support me on GitHub.

yellow-button

Alipay or WeChat. Thanks.


License

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


Description

  • Swift Tools
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Nov 09 2024 18:42:08 GMT-1000 (Hawaii-Aleutian Standard Time)