retrofit 2.0应该算是当前最火的网络请求框架之一,Retrofit更确切的说是对请求参数作了一层封装,通过注解的方式
设置一些列的请求参数,添加了各种支持,如Gson解析,Rxjava的支持,其底层是通过Okhttp去执行网络请求任务,这篇
文章主要分析retrofit 如何通过Api接口创建出具体的Api对象,以及如何将Call 转换成Observeable,Flowable等事
件流对象。先贴一段 Retrofit 创建的模板代码。
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://localhost:4567/")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) // 针对rxjava2.x
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
Api api = retro