EitherCallAdapterFactory

class EitherCallAdapterFactory : CallAdapter.Factory

A CallAdapter.Factory which supports suspend + Either as the return type

Adding this to Retrofit will enable you to return Either from your service methods.

import arrow.core.Either
import retrofit2.http.GET

data class User(val name: String)
data class ErrorBody(val msg: String)
interface MyService {
@GET("/user/me")
suspend fun user(): Either<ErrorBody, User>

@GET("/user/me")
suspend fun userResponse(): Either<ErrorBody, User>
}

Using Either as the return type means that 200 status code and HTTP errors return a value, other exceptions will throw.

ResponseE is similar to retrofit2.Response but uses Either for the response body.

Constructors

Link copied to clipboard
fun EitherCallAdapterFactory()

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open operator override fun get(returnType: Type, annotations: Array<Annotation>, retrofit: Retrofit): CallAdapter<*, *>?