I am using RxJava3 and retrofit but I am unable to get a rxjava3 retrofit-adapter for RxJava3.
Retrofit uses an HTTP client (OkHttp) to execute the network requests. This execution happens on a background thread. When OkHttp client receives a response from the server, it passes the response back to Retrofit.
Class RxJava2CallAdapterFactoryA call adapter which uses RxJava 2 for creating observables. Adding this class to Retrofit allows you to return an Observable , Flowable , Single , Completable or Maybe from service methods.
There is now an official Retrofit implementation with version 2.9.0:
Just use the adapter where you create your Retrofit client:
val rxAdapter = RxJava3CallAdapterFactory.create() retrofit = Retrofit.Builder().baseUrl(baseUrl) .addConverterFactory(MoshiConverterFactory.create(moshi)) .client(httpClient) .addCallAdapterFactory(rxAdapter).build()
And include the RxAdapter dependency in your build.gradle
:
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
https://github.com/square/retrofit/blob/master/CHANGELOG.md#version-290-2020-05-20
Also from the documentation:
Unlike the RxJava 1 and RxJava 2 adapters, the RxJava 3 adapter's create() method will produce asynchronous HTTP requests by default. For synchronous requests use createSynchronous() and for synchronous on a scheduler use createWithScheduler(..)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With