RxJava2 + Retrofit2 http request lib, supports multiple api result data structures and multiple urls. Http请求库,支持同时存在多种返回格式和多个base url
Branch: master
Clone or download
Latest commit 58556e4 Feb 14, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
app gradle update Feb 14, 2019
gradle/wrapper add gradle wrapper Jan 15, 2019
rxretrohttp update gradle Jan 21, 2019
.gitignore first commit Jan 15, 2019
README.md update README Jan 21, 2019
README_cn.md update README Jan 21, 2019
build.gradle gradle update Feb 14, 2019
config.gradle update gradle Jan 21, 2019
gradle.properties Migrate to AndroidX Jan 18, 2019
gradlew update gradlew Jan 21, 2019
gradlew.bat add gradle files Jan 15, 2019
settings.gradle first commit Jan 15, 2019




Android http request lib, supports multiple api result data structures and multiple urls

Http请求库,支持同时存在多种返回格式和多个base url(中文文档

Why RxRetroHttp

In some case, we have to include more than one http request style -- eg. multiple result structure, multiple host address, multiple http settings, etc-- in one app.

This usually happens when we need to use some third party api or combine multiple system in one project.

RxRetroHttp suppose to simplify your http request realization in this situation.

Gradle via JitPack

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }

Add the dependency

dependencies {
    implementation 'com.github.BakerJQ:RxRetroHttp:1.0.3'

How to use


Main Api Request

Initialize the sdk in Application, the code below shows the initialization of the main url request settings

           .setBaseUrl("https://api.github.com/")//your main url
           .setDefaultErrMsg("Github开小差了")//default error hint message
           .setApiResultClass(GithubApiResult.class)//your main api result structure, if not, will use default gson converter

Other Api Request

If your app includes other api request, try the code below


  • You need to do this after you called init()
  • DON'T forget to add the 'Tag' in generateRetroClient() function
  • If you don't set an ApiResultClass, the lib will use GsonConverterFactory as default, this means that the lib will not deal with response logic for you, or you can add your own ResponseConverter
           .setApiResultClass(YourApiResult.class)//other result
           .setBaseUrl("http://host/api/data/")//other url
           .generateRetroClient("YourTag");//other request tag


You can customize your http settings by get and reset the builders, or calling setting functions

Mention: This must be done AFTER init() and BEFORE generateRetroClient() function

Retrofit.Builder retrofitBuilder = RxRetroHttp.getRetrofitBuilder();
OkHttpClient.Builder okHttpBuilder = RxRetroHttp.getOkHttpClientBuilder();

Api Request

Step 1. Define Api Result Structure by Implement IApiResult

Code below is just a simple sample

public class YourApiResult<T> implements IApiResult<T> {
    private int code;//result code
    private String msg;//result message
    private T result;//result data
    //define what means a successful result(eg. code == 1)
    public boolean isSuccess();
    //return the structured data
    public T getData();
    //return the message
    public String getResultMsg();
    //return the code
    public String getResultCode();
    //return the key name of "result" in the response json
    public String getDataField();

Step 2. Define Retrofit Api Service

Define the ApiService, to be mentioned, you DO NOT need to use wrapped api result like "Observable<YourApiResult< TestInfo >>", and add RetroTag annotation if this is a tagged request

public interface YourApiService {
    Observable<TestInfo> getTestInfo();
    Observable<List<TestInfo>> getTestInfo();

Step 3. Call Request

Just define a call like Retrofit



  • Add Retrofit proguard
  • Add OkHttp proguard
  • Add Gson proguard
  • Deal with your data entity


Thanks To (RxEasyHttp


RxRetroHttp is released under the Apache 2.0 license.

Copyright 2019 BakerJ.

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 following link.


Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.