• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

okhttp-RxHttp: 30秒上手,支持协程、RxJava2、RxJava3,史上最优雅的实现文件上传/ ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

okhttp-RxHttp

开源软件地址:

https://gitee.com/327744707/okhttp-RxHttp

开源软件介绍:

RxHttp

English | 中文文档

加我微信 ljx-studio 拉你进微信群(注:不要给我发红包,我脸皮薄,不好意思收,你非要给,请直接Donations,这里手动狗头)

主要优势

1. 30秒即可上手,学习成本极低

2. 史上最优雅的支持 Kotlin 协程

3. 史上最优雅的处理多个BaseUrl及动态BaseUrl

4. 史上最优雅的对错误统一处理,且不打破Lambda表达式

5. 史上最优雅的文件上传/下载/断点下载/进度监听,已适配Android 10

6. 支持Gson、Xml、ProtoBuf、FastJson等第三方数据解析工具

7. 支持Get、Post、Put、Delete等任意请求方式,可自定义请求方式

8. 支持在Activity/Fragment/View/ViewModel/任意类中,自动关闭请求

9. 支持全局加解密、添加公共参数及头部、网络缓存,均支持对某个请求单独设置

请求三部曲

代码表示

//Kotlin + Await             //Kotlin + Flow              //Kotlin + RxJava            //Java + RxJavaRxHttp.get("/server/..")     RxHttp.get("/server/..")     RxHttp.get("/server/..")     RxHttp.get("/server/..")       .add("key", "value")         .add("key", "value")         .add("key", "value")         .add("key", "value")    .toClass<User>()             .toFlow<User>()              .asClass<User>()             .asClass(User.class)    .awaitResult {               .catch {                     .subscribe({                 .subscribe(user -> {        //成功回调                     //异常回调                    //成功回调                     //成功回调         }.onFailure {                }.collect {                  }, {                         }, throwable -> {         //异常回调                     //成功回调                    //异常回调                     //异常回调    }                            }                            })                           });

上手教程

30秒上手教程:30秒上手新一代Http请求神器RxHttp

Flow文档:RxHttp + Flow 三步搞定任意请求

Await文档:RxHttp ,比Retrofit 更优雅的协程体验

RxJava及核心Api介绍:RxHttp 让你眼前一亮的Http请求框架

wiki详细文档:https://github.com/liujingxing/rxhttp/wiki (此文档会持续更新)

自动关闭请求用到的RxLife类,详情请查看RxLife库

更新日志     遇到问题,点击这里,99%的问题都能自己解决

上手准备

Maven依赖点击这里

1、RxHttp目前已适配OkHttp 3.12.0 - 4.9.1版本(4.3.0版本除外), 如你想要兼容21以下,请依赖OkHttp 3.12.x,该版本最低要求 API 9

2、asXxx方法内部是通过RxJava实现的,而RxHttp 2.2.0版本起,内部已剔除RxJava,如需使用,请自行依赖RxJava并告知RxHttp依赖的Rxjava版本

必须

1、配置jitpack到项目的build.gradle文件中
allprojects {    repositories {        maven { url "https://jitpack.io" }    }}
2、配置ava 8或更高
android {    //必须,java 8或更高    compileOptions {        sourceCompatibility JavaVersion.VERSION_1_8        targetCompatibility JavaVersion.VERSION_1_8    }}
3、添加RxHttp依赖
//annotationProcessor无需依赖额外插件plugins {    // kapt/ksp 选其一    // id 'kotlin-kapt'    id("com.google.devtools.ksp") version "1.6.10-1.0.2"}//让IDE知道ksp生成的kotlin代码(仅使用ksp时才需要)kotlin {    sourceSets.debug {        //如果通过productFlavors配置了多渠道,则配置 /../ksp/xxxDebug/kotlin        kotlin.srcDir("build/generated/ksp/debug/kotlin")    }}dependencies {    implementation 'com.squareup.okhttp3:okhttp:4.9.1'      implementation 'com.github.liujingxing.rxhttp:rxhttp:2.8.2'    // ksp/kapt/annotationProcessor 选其一    ksp 'com.github.liujingxing.rxhttp:rxhttp-compiler:2.8.2'  }

ksp、kapt、annotationProcessor 如何选择点击这里

可选

1、配置Coverter

//非必须,根据自己需求选择 RxHttp默认内置了GsonConverterimplementation 'com.github.liujingxing.rxhttp:converter-fastjson:2.8.2'implementation 'com.github.liujingxing.rxhttp:converter-jackson:2.8.2'implementation 'com.github.liujingxing.rxhttp:converter-moshi:2.8.2'implementation 'com.github.liujingxing.rxhttp:converter-protobuf:2.8.2'implementation 'com.github.liujingxing.rxhttp:converter-simplexml:2.8.2'

2、配置RxJava

RxHttp + RxJava3
implementation 'io.reactivex.rxjava3:rxjava:3.1.1'implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'implementation 'com.github.liujingxing.rxlife:rxlife-rxjava3:2.2.1' //管理RxJava3生命周期,页面销毁,关闭请求
RxHttp + RxJava2
implementation 'io.reactivex.rxjava2:rxjava:2.2.8'implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'implementation 'com.github.liujingxing.rxlife:rxlife-rxjava2:2.2.1' //管理RxJava2生命周期,页面销毁,关闭请求
通过ksp传递RxJava版本
ksp {    arg("rxhttp_rxjava", "3.1.1")}
通过kapt传递RxJava版本
kapt {    arguments {        arg("rxhttp_rxjava", "3.1.1")    }}
通过javaCompileOptions传递RxJava版本
android {    defaultConfig {        javaCompileOptions {            annotationProcessorOptions {                arguments = [                    //使用asXxx方法时必须,传入你依赖的RxJava版本                    rxhttp_rxjava: '3.1.1',                 ]            }        }    }}

3、指定RxHttp相关类包名

通过ksp指定RxHttp相关类包名
ksp {    arg("rxhttp_package", "rxhttp")  //指定RxHttp类包名,可随意指定 }
通过kapt指定RxHttp相关类包名
 kapt {    arguments {        arg("rxhttp_package", "rxhttp")  //指定RxHttp类包名,可随意指定    }}
通过javaCompileOptions指定RxHttp相关类包名
android {    defaultConfig {        javaCompileOptions {            annotationProcessorOptions {                arguments = [                    rxhttp_package: 'rxhttp',  //指定RxHttp类包名,可随意指定                ]            }        }    }}

最后,rebuild一下(此步骤是必须的) ,就会自动生成RxHttp类

混淆

RxHttp v2.2.8版本起,无需添加任何混淆规则(内部自带混淆规则),v2.2.8以下版本,请查看混淆规则,并添加到自己项目中

Demo演示

更多功能,请下载apk体验

Donations

如果它对你帮助很大,并且你很想支持库的后续开发和维护,那么你可以扫下方二维码随意打赏我,就当是请我喝杯咖啡或是啤酒,开源不易,感激不尽

rxhttp_donate.png

Licenses

Copyright 2019 liujingxingLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at   http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Y_KLine: iOS-K线发布时间:2022-03-24
下一篇:
ZBLiveBarrage: 直播弹幕发布时间:2022-03-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap