James Lee James Lee - 1 year ago 128
Android Question

Retrofit with rxjava

I'm using Retrofit on Android and I want to use RxJava.

Using only Retrofit was fine but with RxJava is kind of difficult for me.

Could you tell me what to do?

I wrote a interface like below but I'm not sure what option I should use at ???????????

Thanks in advance.

Observable<??????????????> getUserById (@Query("id") int id);

Observable<??????????????> getUserByName (@Query("name") String name);

Observable<??????????????> getAllUsers ();

Answer Source

As you have wrtten, you have an experience with Retrofit. Normally your network call would return Call<{type}>, where type is the object you return from API.

Here you just replace Call with Observable. So your functions would look probably like:

Observable<User> getUserById (@Query("id") int id);

Observable<User> getUserByName (@Query("name") String name);

Observable<List<User>> getAllUsers ();

The tutorial on how to use RxJava with Retrofit can be found here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download