Android链式请求框架(RequestChain)

RequestChain是一个链式请求框架,基于EventChain+Retrofit2+Rxjava2+OkHttp3搭建

  • 使用它可以轻松的处理复杂的请求逻辑

  • 使用Java8或者Kotlin使语法更简洁

  • RequestChain - Git

简单使用

// 用户登陆信息
public static final class LoginBean{ int userId; }

public void login(){
    /*
      ApiManager.getApi().login():通过Retrofit生成请求
      getLifecycle():Activity和Fragment的生命周期观察者,当页面退出的时候自定停止请求
    */
    new RequestEvent(ApiManager.getApi().login(), getLifecycle())
                .addOnRequestListener((OnRequestSucceedListener) s -> mTV_Text.setText(new Gson().toJson(s))) //请求成功监听
                .addOnEventListener(new OnEventDelayWaitBar(this).setShowThrowable(true)) /*请求进度提示监听*/
                .start();

 }

关于链式调用 参考 EventChain

你可能感兴趣的:(Android链式请求框架(RequestChain))