All Projects → MQZHot → Daisynet

MQZHot / Daisynet

Licence: mit
1. - Alamofire与Cache封装 , 更容易存储请求数据. 2. - 封装Alamofire下载,使用更方便

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Daisynet

Netclient Ios
Versatile HTTP Networking in Swift
Stars: ✭ 117 (-64.65%)
Mutual labels:  json, cache, request, alamofire
Deta cache
缓存cache服务器
Stars: ✭ 106 (-67.98%)
Mutual labels:  json, cache, network
Wheel
关于net nio os cache db rpc json web http udp tcp mq 等多个小工具的自定义实现
Stars: ✭ 45 (-86.4%)
Mutual labels:  json, cache, network
Sjnetwork
SJNetwork is a high level network request tool based on AFNetworking and inspired on YTKNetwork.
Stars: ✭ 231 (-30.21%)
Mutual labels:  cache, network, download
Apicache
Simple API-caching middleware for Express/Node.
Stars: ✭ 957 (+189.12%)
Mutual labels:  json, cache
Evreflection
Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift
Stars: ✭ 954 (+188.22%)
Mutual labels:  json, alamofire
Unboxedalamofire
[Deprecated] Alamofire + Unbox: the easiest way to download and decode JSON into swift objects.
Stars: ✭ 65 (-80.36%)
Mutual labels:  json, alamofire
Codablealamofire
An extension for Alamofire that converts JSON data into Decodable objects.
Stars: ✭ 744 (+124.77%)
Mutual labels:  json, alamofire
Zio Tls Http
100% non-blocking, Java NIO only( inspired by zio-nio) , JSON HTTP server based on Scala ZIO library. Everything including TLS encryption modeled as ZIO effects, convenient route DSL similar to https4s, up to 30K TPS local JSON transaction with 25 threads on 6 cores(i7) with ZIO fibers.
Stars: ✭ 71 (-78.55%)
Mutual labels:  json, cache
Moyamapper
快速解析模型工具,支持RxSwift。同时支持缓存功能 【相关手册 https://MoyaMapper.github.io 】
Stars: ✭ 115 (-65.26%)
Mutual labels:  json, cache
hent
A small utility to fetch remote files into buffers
Stars: ✭ 23 (-93.05%)
Mutual labels:  download, request
Subdue
The Subdue graph miner discovers highly-compressing patterns in an input graph.
Stars: ✭ 20 (-93.96%)
Mutual labels:  json, network
Clientserverproject
一个C-S模版,该模版由三部分的程序组成,一个服务端运行的程序,一个客户端运行的程序,还有一个公共的组件,实现了基础的账户管理功能,版本控制,软件升级,公告管理,消息群发,共享文件上传下载,批量文件传送功能。具体的操作方法见演示就行。本项目的一个目标是:提供一个基础的中小型系统的C-S框架,客户端有三种模式,无缝集成访问,winform版本,wpf版本,asp.net mvc版本,方便企业进行中小型系统的二次开发和个人学习。同时网络组件方便的支持读写三菱和西门子PLC的数据,详细见Readme
Stars: ✭ 873 (+163.75%)
Mutual labels:  json, network
Wretch
A tiny wrapper built around fetch with an intuitive syntax. 🍬
Stars: ✭ 2,285 (+590.33%)
Mutual labels:  json, request
miniprogram-network
Redefine the Network API of Wechat MiniProgram (小程序网络库)
Stars: ✭ 93 (-71.9%)
Mutual labels:  download, request
Ky
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Stars: ✭ 7,047 (+2029%)
Mutual labels:  json, request
Serpent
A protocol to serialize Swift structs and classes for encoding and decoding.
Stars: ✭ 281 (-15.11%)
Mutual labels:  json, alamofire
Valuestore
Easily store some values
Stars: ✭ 560 (+69.18%)
Mutual labels:  json, cache
Boltons
🔩 Like builtins, but boltons. 250+ constructs, recipes, and snippets which extend (and rely on nothing but) the Python standard library. Nothing like Michael Bolton.
Stars: ✭ 5,671 (+1613.29%)
Mutual labels:  json, cache
Data Store
Easily get, set and persist config data. Fast. Supports dot-notation in keys. No dependencies.
Stars: ✭ 120 (-63.75%)
Mutual labels:  json, cache

DaisyNet

AlamofireCache的封装实现对网络数据的缓存,可以存储JSON,String,Data.

使用

1. 网络请求

注意: 如果你的参数中带有时间戳、token等变化的参数,这些参数需要写在dynamicParams参数中,避免无法读取缓存

func request(
    _ url: String,
    method: HTTPMethod = .get,
    params: Parameters? = nil,
    dynamicParams: Parameters? = nil,
    encoding: ParameterEncoding = URLEncoding.default,
    headers: HTTPHeaders? = nil)
    -> RequestTaskManager
  • 缓存数据只需要调用.cache(true),不调用或者.cache(false)则不缓存
  • 调用responseCacheAndString可以先读取缓存数据,再读取网络数据
  • 通过isCacheData属性可以区分缓存数据还是网络数据
DaisyNet.request(url, params: params).cache(true).responseCacheAndJson { value in
    switch value.result {
    case .success(let json):
        if value.isCacheData {
            print("我是缓存的")
        } else {
            print("我是网络的")
        }
    case .failure(let error):
        print(error)
    }
}
  • 你也可以分别读取缓存数据和网络数据,如下代码
  • 调用cacheJson方法获取缓存数据,调用responseJson获取网络数据
DaisyNet.request(url, params: params).cache(true).cacheJson { json in
        print("我是缓存的")
    }.responseJson { response in
    print("我是网络的")
}
  • 如果你不需要缓存,可以直接调用responseJson方法
DaisyNet.request(url).responseString { response in
    switch response {
    case .success(let value): print(value)
    case .failure(let error): print(error)
    }
}
  • 同理,如果你要缓存Data或者String,与JSON是相似的
/// 先读取缓存,再读取网络数据
DaisyNet.request(url).cache(true).responseCacheAndString { value in }
DaisyNet.request(url).cache(true).responseCacheAndData { value in }
/// 分别获取缓存和网络数据
DaisyNet.request(url).cache(true).cacheString { string in
        print("我是缓存的")
    }.responseString { response in
    print("我是网络的")
}
  • 取消请求
DaisyNet.cancel(url, params: params)
  • 清除缓存
/// 清除所有缓存
func removeAllCache(completion: @escaping (Bool)->())
/// 根据url和params清除缓存
func removeObjectCache(_ url: String, params: [String: Any]? = nil, completion: @escaping (Bool)->())

2. 下载

DaisyNet.download(url).downloadProgress { progress in
        /// 下载进度
    }.response { response in
    /// 下载完成
}
  • 如果正在下载中退出当前界面,再次进入时可以通过以下方法获取下载进度,并改变UI
DaisyNet.downloadProgress(url) {
        print($0)
    }?.response(completion: { _ in
    print("下载完成")
})
  • 获取下载状态
DaisyNet.downloadStatus(url)
  • 获取下载百分比
DaisyNet.downloadPercent(url)
  • 获取下载完成后文件所在位置
DDaisyNet.downloadFilePath(url)
  • 删除某个下载
DaisyNet.downloadDelete(url)
  • 取消某个下载
DaisyNet.downloadCancel(url)
  • 取消所有下载
DaisyNet.downloadCancelAll()

Install

1.pod 'DaisyNet'

2.pod install / pod update

Author

LICENSE

DaisyNet is released under the MIT license. See LICENSE for details.

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].