GitHunt

Kotlin version
MavenCentral
Snapshot

Build
Coverage
Quality
Tech debt

Network Either

Ktor

Usage

val client: HttpClient = HttpClient(MockEngine) {
    install(NetworkEitherPlugin)
    install(ContentNegotiation) {
        json(defaultJson)
    }
}

@Serializable
data class DogDTO(val id: Int, val name: String, val age: Int)

@Serializable
data class ErrorDTO(val message: String)

val response: NetworkEither<ErrorDTO, DogDTO> = client.get("dog").body()
response.fold(
    failure = { ... },
    success = { ... },
)

Check all available functions in the
NetworkEither class
.

Check the tests
for more examples.

Retrofit

Usage

val retrofit =
    Retrofit
        .Builder()
        .baseUrl("org.example.com")
        .addCallAdapterFactory(NetworkEitherCallAdapterFactory())
        .build()

interface DogService {

    @GET("dog")
    suspend fun getDog(): NetworkEither<ErrorDTO, DogDTO>
}

val service: DogService = retrofit.create()
val response: NetworkEither<ErrorDTO, DogDTO> = service.getDog()
response.fold(
    failure = { ... },
    success = { ... },
)

Check the tests
for more examples.

Docs

All docs are available on the network-either-kmp website

Download from MavenCentral

  • NetworkEither, pretty printing logger and ResourceEither mappers
implementation("com.javiersc.network:network-either:$version")

Languages

Kotlin99.8%CSS0.2%

Contributors

Created December 19, 2020
Updated July 5, 2025