[MSANJANA]
← BACK TO DIARY
MOBILE2025.12.25

Retrofit CallAdapters

Retrofit defines CallAdapter to transform its internal Call<T> into whatever return type you want. CallAdapter is about adapting return types at runtime.

Retrofit CallAdapters

Retrofit defines CallAdapter to transform its internal Call into whatever return type you want. CallAdapter is about adapting return types at runtime.

Retrofit CallAdapter Flow

Retrofit supports Kotlin suspend functions natively.

Retrofit still uses external adapters for:

  • RxJava
  • Java 8 CompletableFuture
  • Guava
  • Those are still implemented as CallAdapter.Factory extensions you add manually.

    Docs and Android style guidelines favor Flow/suspend at the repository layer.

    Example

    interface ApiService {
        @GET("users")
        suspend fun getUsers(): List
    }
    

    No Call and no adapter needed for coroutines.

    Build Retrofit

    val retrofit = Retrofit.Builder()
        .baseUrl("https://example.com/")
        .addConverterFactory(GsonConverterFactory.create())
        .build()
    

    RxJava Example

    val retrofit = Retrofit.Builder()
        .baseUrl("https://example.com/")
        .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
        .addConverterFactory(GsonConverterFactory.create())
        .build()
    

    Retrofit Setup Diagram

    #Retrofit#Android#Kotlin#RxJava