Lychee
项目地址:VipMinF/Lychee
简介: 基于 retrofit 实现的网络请求库,支持多任务上传下载,断点续传,可选 Rxjava,Rxjava2,retrofit 原生请求
标签:
介绍
Lychee
是一个基于 Retrofit2 实现的轻量级网络请求库,支持多任务上传,下载,断点续传,使用简单,方便。使用注解简化了 Retrofit2 原有的文件上传方式,支持添加通用请求参数,参数签名(文件使用 md5)
相关文章
- 基于 Retrofit2 实现的 LycheeHttp
- 基于 Retrofit2 实现的 LycheeHttp-使用动态代理实现上传
- 基于 Retrofit2 实现的 LycheeHttp-多任务下载的实现
用法
初始化配置
override fun onCreate() {
super.onCreate()
LycheeHttp.init(MyCoreConfig(this))
}
下载的 API 定义
下载只需要使用 Download
注解 API 就可以啦
@Download
@GET("https://xxxx/xxxx.apk")
fun download(): Call<DownloadBean>
上传的 API 定义
- 根据文件名称的后缀名获取,使用
Upload
进行注解@Upload @Multipart @POST("http://xxx/xxx") fun upload(@Part("file") file: File): Call<ResultBean<UploadResult>>
- 对某个 file 进行注解,使用
FileType("png")
或者FileType("image/png")
@Multipart @POST("http:/xxx/xxx") fun upload(@Part("file") @FileType("png") file: File): Call<ResultBean<UploadResult>>