All Projects → liujingxing → Okhttp Rxhttp

liujingxing / Okhttp Rxhttp

Licence: apache-2.0
🔥🔥🔥 Based on OkHttp encapsulation, support Kotlin Coroutines、RxJava2、RxJava3; 30s to get started.

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to Okhttp Rxhttp

Wanandroid
WanAndroid客户端,项目基于 Material Design + MVP +dagger2 + RxJava + Retrofit + Glide + greendao 等架构进行设计实现,极力打造一款 优秀的玩Android https://www.wanandroid.com 客户端,是一个不错的Android应用开发学习参考项目
Stars: ✭ 223 (-92.97%)
Mutual labels:  rxjava2, okhttp3, retrofit2
WanAndroid
wanandroid的Kotlin版,采用Android X
Stars: ✭ 20 (-99.37%)
Mutual labels:  rxjava2, retrofit2, okhttp3
blueprint
Architectural frameworks and toolkits for bootstrapping modern Android codebases.
Stars: ✭ 57 (-98.2%)
Mutual labels:  rxjava2, kotlin-coroutines, rxjava3
Jbusdriver
这是去幼儿园的班车(滑稽
Stars: ✭ 2,056 (-35.14%)
Mutual labels:  rxjava2, okhttp3, retrofit2
StackOverFlowApi
working with Stack OverFlow Api
Stars: ✭ 24 (-99.24%)
Mutual labels:  rxjava2, retrofit2, okhttp3
Httprequest
基于Retrofit2+RxJava2+OkHttp3的网络请求框架,可以完美的应用到组件化、MVP模式等项目中
Stars: ✭ 181 (-94.29%)
Mutual labels:  rxjava2, okhttp3, retrofit2
Atoms-mvp
A component architecture for android applications based on MVP
Stars: ✭ 63 (-98.01%)
Mutual labels:  rxjava2, retrofit2, okhttp3
Rxapp
Stars: ✭ 108 (-96.59%)
Mutual labels:  rxjava2, okhttp3, retrofit2
RxHttp
基于RxJava2+Retrofit+OkHttp4.x封装的网络请求类库,亮点多多,完美兼容MVVM(ViewModel,LiveData),天生支持网络请求和生命周期绑定,天生支持多BaseUrl,支持文件上传下载进度监听,支持断点下载,支持Glide和网络请求公用一个OkHttpClient⭐⭐⭐
Stars: ✭ 25 (-99.21%)
Mutual labels:  rxjava2, retrofit2, okhttp3
iMoney
iMoney 金融项目
Stars: ✭ 55 (-98.26%)
Mutual labels:  rxjava2, retrofit2, okhttp3
Bilisoleil Kotlin
An unofficial bilibili client for android --kotlin+rxjava2+mvp+okhttp3+retrofit2+dagger2
Stars: ✭ 139 (-95.62%)
Mutual labels:  rxjava2, okhttp3, retrofit2
codeKK-Android
http://p.codekk.com/
Stars: ✭ 29 (-99.09%)
Mutual labels:  rxjava2, retrofit2, okhttp3
Nice Knowledge System
📚不积跬步无以至千里,每天进步一点点,Passion,Self-regulation,Love and Share
Stars: ✭ 137 (-95.68%)
Mutual labels:  rxjava2, okhttp3, retrofit2
Awesome Wanandroid
⚡致力于打造一款极致体验的 http://www.wanandroid.com/ 客户端,知识和美是可以并存的哦QAQn(*≧▽≦*)n
Stars: ✭ 2,525 (-20.35%)
Mutual labels:  rxjava2, okhttp3, retrofit2
Android Cnblogs
🔥🔥 博客园Android端开源项目,界面简洁清新。
Stars: ✭ 127 (-95.99%)
Mutual labels:  rxjava2, okhttp3, retrofit2
RxJava2Demo
RxJava 2.X Retrofit OkHttp demo
Stars: ✭ 29 (-99.09%)
Mutual labels:  rxjava2, retrofit2, okhttp3
Bilisoleil
An unofficial bilibili client for android --rxjava2+mvp+okhttp3+retrofit2+dagger2
Stars: ✭ 430 (-86.44%)
Mutual labels:  rxjava2, okhttp3, retrofit2
Todo List
待办事项APP
Stars: ✭ 45 (-98.58%)
Mutual labels:  rxjava2, okhttp3, retrofit2
eyepetizer kotlin
一款仿开眼短视频App,分别采用MVP、MVVM两种模式实现。一、组件化 + Kotlin + MVP + RxJava + Retrofit + OkHttp 二、组件化 + Kotlin + MVVM + LiveData + DataBinding + Coroutines + RxJava + Retrofit + OkHttp
Stars: ✭ 83 (-97.38%)
Mutual labels:  rxjava2, retrofit2, okhttp3
situp android proj
🚀一个基组件化、模块化、MVP + MVVM 计划 App,兼容安卓 10.0 9.0 8.0 等 🔥a app like keep, you can edit your plans here, and you can share your life to others by post, too.🔥
Stars: ✭ 15 (-99.53%)
Mutual labels:  rxjava2, retrofit2, okhttp3

RxHttp

English | 中文文档

A type-safe HTTP client for Android. Written based on OkHttp

sequence_chart_en.jpg

//Kotlin + Await             //Kotlin + Flow              //Kotlin + RxJava            //Java + RxJava
RxHttp.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 -> {
        //Success                    //Failure                    //Success                    //Success     
    }.onFailure {                }.collect {                  }, {                         }, throwable -> { 
        //Failure                    //Success                    //Failure                    //Failure
    }                            }                            })                           });

1、Feature

  • Support kotlin coroutines, RxJava2, RxJava3

  • Support Gson, Xml, ProtoBuf, FastJson and other third-party data parsing tools

  • Supports automatic closure of requests in FragmentActivity, Fragment, View, ViewModel, and any class

  • Support global encryption and decryption, add common parameters and headers, network cache, all support a request set up separately

2、usage

1、Adding dependencies and configurations

Required

1、Add jitpack to your build.gradle
allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}
2、Java 8 or higher
android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
3、Add RxHttp dependency
plugins {
    // kapt/ksp choose one
    // id 'kotlin-kapt'
    id("com.google.devtools.ksp") version "1.6.10-1.0.2"
}

//Make IDE aware of generated code if you use ksp
kotlin {
    sourceSets.debug {
        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 choose one
    ksp 'com.github.liujingxing.rxhttp:rxhttp-compiler:2.8.2'
 }

Optional

1、Coverter

implementation '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, Automatic close request
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, Automatic close request
ksp passes the RxJava version
ksp {
    arg("rxhttp_rxjava", "3.1.1")
}
Kapt passes the RxJava version
kapt {
    arguments {
        arg("rxhttp_rxjava", "3.1.1")
    }
}
javaCompileOptions passes the RxJava version
android {
    defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [
                    rxhttp_rxjava: '3.1.1', 
                ]
            }
        }
    }
}

3、set RxHttp class package name

ksp pass package name
ksp {
     arg("rxhttp_package", "rxhttp.xxx")
}
kapt pass package name
kapt {
    arguments {
       arg("rxhttp_package", "rxhttp.xxx") 
    }
}
javaCompileOptions pass package name
android {
    defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [
                    rxhttp_package: 'rxhttp.xxx'
                ]
            }
        }
    }
}

Finally, rebuild the project, which is necessary

2、Initialize the SDK

This step is optional

RxHttpPlugins.init(OkHttpClient)  
    .setDebug(boolean)  
    .setOnParamAssembly(Function)
    ....

3、Configuration BaseUrl

This step is optional

public class Url {

    //Add the @defaultDomain annotation to BASE_URL
    @DefaultDomain
    public static BASE_URL = "https://..."
}

4、Perform the requested

// java
RxHttp.get("/service/...")   //1、You can choose get,postFrom,postJson etc
    .addQuery("key", "value")               //add query param
    .addHeader("headerKey", "headerValue")  //add request header
    .asClass(Student.class)  //2、Use the asXxx method to determine the return value type, customizable
    .subscribe(student -> {  //3、Subscribing observer
        //Success callback,Default IO thread
    }, throwable -> {
        //Abnormal callback
    });

// kotlin 
RxHttp.postForm("/service/...")          //post FormBody
    .add("key", "value")                 //add param to body
    .addQuery("key1", "value1")          //add query param
    .addFile("file", File(".../1.png"))  //add file to body
    .asClass<Student>()           
    .subscribe({ student ->       
        //Default IO thread
    }, { throwable ->
        
    })

// kotlin coroutine
val students = RxHttp.postJson("/service/...")  //1、post {application/json; charset=utf-8}
    .toList<Student>()                          //2、Use the toXxx method to determine the return value type, customizable
    .await()                                    //3、Get the return value, await is the suspend method

3、Advanced usage

 1、Close the request

//In Rxjava2 , Automatic close request
RxHttp.get("/service/...")
    .asString()
    .as(RxLife.as(this))  //The Activity destroys and automatically closes the request
    .subscribe(s -> {
        //Default IO thread
    }, throwable -> {

    });

//In Rxjava3 , Automatic close request
RxHttp.get("/service/...")
    .asString()
    .to(RxLife.to(this))  //The Activity destroys and automatically closes the request
    .subscribe(s -> {
        //Default IO thread
    }, throwable -> {
        
    });


//In RxJava2/RxJava3, close the request manually
Disposable disposable = RxHttp.get("/service/...")
    .asString()
    .subscribe(s -> {
        //Default IO thread
    }, throwable -> {
        
    });

disposable.dispose(); //Close the request at the appropriate time

4、ProGuard

If you are using RxHttp v2.2.8 or above the shrinking and obfuscation rules are included automatically. Otherwise you must manually add the options in rxhttp.pro.

5、Donations

If this project helps you a lot and you want to support the project's development and maintenance of this project, feel free to scan the following QR code for donation. Your donation is highly appreciated. Thank you!

rxhttp_donate.png

Licenses

Copyright 2019 liujingxing

Licensed 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.0

Unless required by applicable law or agreed to in writing, software
distributed 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 and
limitations under the License.
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].