I use github ready-made package modules rxretrofitlibrary
Step by step encapsulation http://blog.csdn.net/wzgiceman/article/details/51939574
The column moves http://blog.csdn.net/column/details/13297.html
The blogger's three versions of gitbub achievements:
https://github.com/wzgiceman/RxjavaRetrofitDemo-string-master
https://github.com/wzgiceman/RxjavaRetrofitDemo-master
https://github.com/wzgiceman/Rx-Retrofit
I use RxjavaRetrofitDemo-string-master modules
The network request contains cache function, including retry function
1. Test http://www.iteye.com/blogs
public class IteyeBlogsApi extends BaseApi { public IteyeBlogsApi(){ setBaseUrl("http://www.iteye.com/"); } @Override public Observable getObservable(Retrofit retrofit) { IteyeGetBlogsService api= retrofit.create(IteyeGetBlogsService.class); return api.getAllBlogs(); } }
public interface IteyeGetBlogsService { @GET("blogs") Observable<String> getAllBlogs(); }
myApi = new IteyeBlogsApi();
manager = new HttpManager(this, this);
case R.id.btn_rx_text_iteye: Log.i("baoyou","myApi ===== start"); manager.doHttpDeal(myApi); break;
result test
2. Test a local rest service
public interface LocalUserRestService { @GET("user/list") Observable<String> getAllUsers(); }
public class LocalUserRestApi extends BaseApi { public LocalUserRestApi () { setBaseUrl("http://192.168.50.61:8081/rest/rest/"); } @Override public Observable getObservable(Retrofit retrofit) { LocalUserRestService api= retrofit.create(LocalUserRestService.class); return api.getAllUsers(); } }
Log.i("baoyou","userRestApi ===== new start"); userRestApi = new LocalUserRestApi(); Log.i("baoyou","userRestApi ===== new start");
@Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_rx_text_rest_user: Log.i("baoyou","userRestApi ===== start"); manager.doHttpDeal(userRestApi); Log.i("baoyou","userRestApi ===== end"); break;
Donate to developers
Driven by interest, I write 免费
something with joy and sweat. I hope you like my work and can support it at the same time. Of course, if you have money to support a money field (support Alipay and WeChat donations, join the it technology buckle group), but have no money to support a personal field, thank you.
Thank you for your sponsorship, I will do better!