Class RxJavaCallAdapterFactory

java.lang.Object
retrofit2.CallAdapter.Factory
retrofit2.adapter.rxjava.RxJavaCallAdapterFactory

public final class RxJavaCallAdapterFactory
extends retrofit2.CallAdapter.Factory
A call adapter which uses RxJava for creating observables.

Adding this class to Retrofit allows you to return an Observable, Single, or Completable from service methods.


 interface MyService {
   @GET("user/me")
   Observable<User> getUser()
 }
 
There are three configurations supported for the Observable or Single type parameter:
  • Direct body (e.g., Observable<User>) calls onNext with the deserialized body for 2XX responses and calls onError with HttpException for non-2XX responses and IOException for network errors.
  • Response wrapped body (e.g., Observable<Response<User>>) calls onNext with a Response object for all HTTP responses and calls onError with IOException for network errors
  • Result wrapped body (e.g., Observable<Result<User>>) calls onNext with a Result object for all HTTP responses and errors.

Note: Support for Single and Completable is experimental and subject to backwards-incompatible changes at any time since both of these types are not considered stable by RxJava.

  • Method Summary

    Modifier and Type Method Description
    static RxJavaCallAdapterFactory create()
    Returns an instance which creates synchronous observables that do not operate on any scheduler by default.
    static RxJavaCallAdapterFactory createAsync()
    Returns an instance which creates asynchronous observables.
    static RxJavaCallAdapterFactory createWithScheduler​(rx.Scheduler scheduler)
    Returns an instance which creates synchronous observables that subscribe on scheduler by default.
    retrofit2.CallAdapter<?,​?> get​(java.lang.reflect.Type returnType, java.lang.annotation.Annotation[] annotations, retrofit2.Retrofit retrofit)  

    Methods inherited from class retrofit2.CallAdapter.Factory

    getParameterUpperBound, getRawType

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static RxJavaCallAdapterFactory create()
      Returns an instance which creates synchronous observables that do not operate on any scheduler by default.
    • createAsync

      public static RxJavaCallAdapterFactory createAsync()
      Returns an instance which creates asynchronous observables.
    • createWithScheduler

      public static RxJavaCallAdapterFactory createWithScheduler​(rx.Scheduler scheduler)
      Returns an instance which creates synchronous observables that subscribe on scheduler by default.
    • get

      @Nullable public retrofit2.CallAdapter<?,​?> get​(java.lang.reflect.Type returnType, java.lang.annotation.Annotation[] annotations, retrofit2.Retrofit retrofit)
      Specified by:
      get in class retrofit2.CallAdapter.Factory