Pircate / Rxnetwork
Licence: mit
A swift network library based on Moya/RxSwift.
Stars: ✭ 43
Programming Languages
swift
15916 projects
Projects that are alternatives of or similar to Rxnetwork
Moyamapper
快速解析模型工具,支持RxSwift。同时支持缓存功能 【相关手册 https://MoyaMapper.github.io 】
Stars: ✭ 115 (+167.44%)
Mutual labels: rxswift, cache, moya
Boilerplate
Swift 4 and Using MVVM architecture(Rxswfit + Moya) to implement Github client demo.
Stars: ✭ 102 (+137.21%)
Mutual labels: rxswift, moya
Evreflection
Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift
Stars: ✭ 954 (+2118.6%)
Mutual labels: rxswift, moya
Ios
A sample project demonstrating MVVM, RxSwift, Coordinator Pattern, Dependency Injection
Stars: ✭ 49 (+13.95%)
Mutual labels: rxswift, moya
Swift-Viper-Weather-App
iOS app with Clean Architecture
Stars: ✭ 20 (-53.49%)
Mutual labels: rxswift, moya
iOS Started Kit
iOS Started Kit: Clean Architecture + RxSwift + Moya
Stars: ✭ 12 (-72.09%)
Mutual labels: rxswift, moya
Swift
💻 Swift - Boilerplate Front : RxSwift, ReactorKit, JWT, Moya (Beta)
Stars: ✭ 17 (-60.47%)
Mutual labels: rxswift, moya
Swifthub
GitHub iOS client in RxSwift and MVVM-C clean architecture
Stars: ✭ 2,330 (+5318.6%)
Mutual labels: rxswift, moya
GitTime
GitTime is GitHub Tracking App. Using ReactorKit, RxSwift, Moya.
Stars: ✭ 55 (+27.91%)
Mutual labels: rxswift, moya
Rxswiftexamples
Examples and resources for RxSwift.
Stars: ✭ 930 (+2062.79%)
Mutual labels: rxswift, moya
Sst Elements
SST Architectural Simulation Components and Libraries
Stars: ✭ 36 (-16.28%)
Mutual labels: cache
Videoplayer
AVPlayer control and monitoring made easy (with Rx)
Stars: ✭ 29 (-32.56%)
Mutual labels: rxswift
Python Diskcache
Python disk-backed cache (Django-compatible). Faster than Redis and Memcached. Pure-Python.
Stars: ✭ 992 (+2206.98%)
Mutual labels: cache
RxNetwork
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
- iOS 9.0
- Swift 5.0
Installation
RxNetwork is available through CocoaPods or Carthage. To install it, simply add the following line to your Podfile or Cartfile:
Podfile
pod 'RxNetwork'
缓存
pod 'RxNetwork/Cacheable'
Cartfile
github "Pircate/RxNetwork"
Usage
Import
import RxNetwork
Configuration
Network.Configuration.default.timeoutInterval = 20
Network.Configuration.default.plugins = [NetworkIndicatorPlugin()]
Network.Configuration.default.replacingTask = { target in
// configure common parameters etc.
switch target.task {
case let .requestParameters(parameters, encoding):
let params: [String: Any] = ["token": "", "sign": "", "body": parameters]
return .requestParameters(parameters: params, encoding: encoding)
default:
return target.task
}
}
// or
let configuration = Network.Configuration()
configuration.timeoutInterval = 20
configuration.plugins = [NetworkIndicatorPlugin()]
Network.Configuration.default = configuration
Allow storage strategy
确保缓存的数据是正确的 JSON 格式,否则解析数据的时候会失败导致序列抛出异常。
如下,仅当 code 为 200 时返回的数据才是正确的 JSON 格式。
extension Storable where Self: TargetType {
public var allowsStorage: (Moya.Response) -> Bool {
return {
do {
return try $0.mapCode() == 200
} catch {
return false
}
}
}
}
Request without cache
StoryAPI.latest
.request()
.map(StoryListModel.self)
.subscribe(onSuccess: { (model) in
}).disposed(by: disposeBag)
Request with cache
/*
{
"top_stories": []
}
*/
StoryAPI.latest
.onCache(StoryListModel.self, { (model) in
})
.request()
.subscribe(onSuccess: { (model) in
})
.disposed(by: disposeBag)
StoryAPI.latest
.cache
.request()
.map(StoryListModel.self)
.subscribe(onNext: { (model) in
}).disposed(by: disposeBag)
/*
{
"code": 2000,
"message": "Ok",
"result": []
}
*/
TestTarget.test(count: 10)
.onCache([TestModel].self, { (models) in
})
.requestObject()
.subscribe(onSuccess: { (models) in
})
.disposed(by: disposeBag)
TestTarget.test(count: 10)
.cache
.request()
.mapObject([TestModel].self)
.subscribe(onNext: { (models) in
})
.disposed(by: disposeBag)
Cacheable
为 target
提供缓存功能,请遵循 Cacheable
协议
enum API: TargetType, Cacheable {
case api
// 设置缓存过期时间
var expiry: Expiry {
return .never
}
}
Author
Pircate, [email protected]
License
RxNetwork is available under the MIT license. See the LICENSE file for more info.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].