Rxify the API call

Reactive programming has already become very popular among developers. In most android apps, RxJava/Android is used in obvious ways. API calls are one of those use cases. We have attempted to make an API call using RxJava. With Kotlin, you will hardly see any verbosity and the code is so readable. 

You might be wondering how the magic is happening here. Lambda functions are the answer. All those curly brackets you see here are lambda functions. I have highlighted them in bold:

override fun getPolls() {    RetrofitAPIClient.getClient().create(PollService::class.java)            .getPolls()            .subscribeOn(Schedulers.io())            .observeOn(AndroidSchedulers.mainThread())            .doOnSubscribe {                view.showLoader()            }            .doFinally {                view.hideLoader()            }            .subscribe( ...

Get Hands-On Serverless Applications with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.