An Adapter
for adapting RxJava 3.x types.
Available types:
Observable<T>
,Observable<Response<T>>
, andObservable<Result<T>>
whereT
is the body type.Flowable<T>
,Flowable<Response<T>>
andFlowable<Result<T>>
whereT
is the body type.Single<T>
,Single<Response<T>>
, andSingle<Result<T>>
whereT
is the body type.Maybe<T>
,Maybe<Response<T>>
, andMaybe<Result<T>>
whereT
is the body type.Completable
where response bodies are discarded.
Add RxJava3CallAdapterFactory
as a Call
adapter when building your Retrofit
instance:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://example.com/")
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
.build();
Your service methods can now use any of the above types as their return type.
interface MyService {
@GET("/user")
Observable<User> getUser();
}
By default, create()
will produce reactive types which execute their HTTP requests asynchronously
on a background thread. There are two other ways to control the threading on which a request
occurs:
- Use
createSynchronous()
and callsubscribeOn
on the returned reactive type with aScheduler
of your choice. - Use
createWithScheduler(Scheduler)
to supply a default subscriptionScheduler
.
Download the latest JAR or grab via Maven:
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>adapter-rxjava3</artifactId>
<version>latest.version</version>
</dependency>
or Gradle:
implementation 'com.squareup.retrofit2:adapter-rxjava3:latest.version'
Snapshots of the development version are available in Sonatype's snapshots
repository.