14

As Retrofit docs represent Call enqueue method in Retrofit is :

Asynchronously send the request and notify callback of its response or if an error occurred talking to the server, creating the request, or processing the response.

and Rxjava according to this tutorial is :

RxJava and RxAndroid libraries allow us to easily do async processing using principles of functional reactive programming

it seems these two have the same approach. What is advantages and disadvantages of each? Which one is better to use?

alizeyn
  • 2,300
  • 1
  • 20
  • 30

1 Answers1

5

I won't say they have the same approach. Retrofit is specifically designed for API calls which Synchronously or Asynchronously calls an API for you (you can specify that). while RxJava & RxAndroid can do the similar for you (i.e doing some tasks in sync or async), it is not limited to API call only. You can do many wonders with RxJava/Android

As you have quoted that

RxJava and RxAndroid libraries allow us to easily do async processing using principles of functional reactive programming

RxJava & RxAndroid does that with principles of Functional Reactive Programming(FRP). FRP has nothing to do with Retrofit & hence they are not same & can't be compared.

You can also use RxJava/Android with Retrofit for calling API in FRP Pattern.

Please read this so you can get more idea about FRP:

You should read this as well for understanding what operators does RxJava gives & how you could use them

In the end, if by Asynchronous you only meant API calls, then Retrofit is better doing that as it's specially designed for that and if by Asynchronous you meant some other tasks like resource intensive or so, then obviously RxJava/Android will be better if you want async task in FRP pattern like Observer or Observable.

Sandip Fichadiya
  • 3,430
  • 2
  • 21
  • 47
  • 1
    Yes, It's true Rxjava is generic and Retrofit Call enqueue is for API call but they have a thing in common and that's async processing. So I guess that's totally comparable. So you say the difference is in Rxjava I'm using FRP pattern and that's all ? – alizeyn Sep 07 '17 at 06:10
  • 1
    FRP Pattern is not "That's all". It's really hard to explain what FRP is all about here. You could go through the articles I have linked. While you are focusing more on async processing available on both, it's simple that Retrofit can do Async calls better but it's only limited to API calls, while you could use Rx for doing any resource intensive task asynchronously & notify to all observers. Hope this helps :) – Sandip Fichadiya Sep 07 '17 at 06:28
  • Which approach is more common for Android devs, which one do you use? – IgorGanapolsky Jun 01 '18 at 14:13
  • I use retrofit with RxJava adapter – Sandip Fichadiya Jun 01 '18 at 15:54