Why is RxJava so important with retrofit?

Over the past 3 weeks I’ve been learning new topics about networking in android and figure out powerful libraries you can use to get the job done.

What is RxJava?

RxJava is a Java VM implementation of ReactiveX (Reactive Extensions): a library for composing asynchronous and event-based programs by using observable sequences.”

In other words we react to the data as it comes, we manage data when we need it, accesing through events changes through observers.

There are three important concepts that we use alot in RxJava:

  1. Observables
  2. Subscribers (Observers)

Observables

The observable is actually the one who starts everything, these guys are the ones that emit the whole data. An observable may emit any number of items and any type of data. It can terminate either successfully or with an error.

Subscribers

These buddies over here are the ones who subscribe to the observables to reach out the data provided by the observable. The onNext() is called in each subscriber to pull out the data, when it’s done it calls the onComplete() method.

When does Retrofit come?

Retrofit is a REST Client for Android and Java by Square. Retrofit is an http type-safe for android and java, with this awesome library we get to make http request easier because all the parsing JSON is already done and gets all the data into Java Objects.

Combining these two technologies

When creating Observables and managing them with http request you get to handle all these datas in a asynchronous way. In that you can get more control of you data handling in a better way without complicating yourself with thread problems.