Giter Club home page Giter Club logo

annawang1 / okhttp-rxhttp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from liujingxing/rxhttp

0.0 1.0 0.0 5.91 MB

OkHttp+RxJava 30秒上手,新一代Http请求神器,史上最优雅的实现文件上传/下载/进度监听、动态/多域名、缓存;支持第三方数据解析工具、自定义请求、自动关闭请求等等

Home Page: https://juejin.im/post/5ded221a518825125d14a1d4

License: Apache License 2.0

Java 98.40% Kotlin 1.60%

okhttp-rxhttp's Introduction

Download

RxHttp主要优势

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

2. 史上最优雅的处理网络缓存

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

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

5. 史上最优雅的实现文件上传/下载及进度的监听,且支持断点下载

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

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

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

9. 支持统一加解密,且可对单个请求设置是否加解密

10. 支持添加公共参数/头部,且可对单个请求设置是否添加公共参数/头部

Gradle依赖

dependencies {
   implementation 'com.rxjava.rxhttp:rxhttp:1.4.0'
   annotationProcessor 'com.rxjava.rxhttp:rxhttp-compiler:1.4.0' //注解处理器,生成RxHttp类

   implementation 'com.rxjava.rxlife:rxlife:1.1.0'  //页面销毁,关闭请求,非必须
   implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'  //切换主线程,非必须

   //Converter 根据自己需求选择  非必须  RxHttp默认内置了GsonConverter
   implementation 'com.rxjava.rxhttp:converter-jackson:1.4.0'
   implementation 'com.rxjava.rxhttp:converter-fastjson:1.4.0'
   implementation 'com.rxjava.rxhttp:converter-protobuf:1.4.0'
   implementation 'com.rxjava.rxhttp:converter-simplexml:1.4.0'
}

注:kotlin用户,请使用kapt替代annotationProcessor

RxHttp&RxLife 交流群:378530627

准备工作

RxHttp 要求项目使用Java 8,请在 app 的 build.gradle 添加以下代码

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

此时rebuild一下项目,就能看到RxHttp类了,到这,准备工作完毕,即可直接调用RxHttp发送请求了。

上手教程

30秒上手教程:https://juejin.im/post/5cfcbbcbe51d455a694f94df

掘金详细文档:https://juejin.im/post/5ded221a518825125d14a1d4

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

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

API兼容

RxHttp最低要求为API 15,但是由于内部依赖OkHttp 3.14.1版本, 最低要求为API 21。 如果你要的项目要兼容到API 15,请将RxHttp内部的OkHttp剔除,并引入低版本的OkHttp,如下:

implementation('com.rxjava.rxhttp:rxhttp:x.x.x') { //xxx为RxHttp最新版本
    exclude group: "com.squareup.okhttp3"
}
implementation 'com.squareup.okhttp3:okhttp:3.12.6' //此版本最低要求 API 9

混淆

RxHttp作为开源库,可混淆,也可不混淆,如果不希望被混淆,请在proguard-rules.pro文件添加以下代码

-keep class rxhttp.**{*;}

小技巧

在这教大家一个小技巧,由于使用RxHttp发送请求都遵循请求三部曲,故我们可以在android studio 设置代码模版,如下

image

如图设置好后,写代码时,输入rp,就会自动生成模版,如下:

image

Demo演示

更多功能,请下载Demo体验

Donations

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

image

okhttp-rxhttp's People

Contributors

liujingxing10000 avatar liujingxing avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.