network-either-kmp

Facilitates handling of network operations by providing utilities for either pattern, pretty printing logs, and resource mapping. Documentation and integration details accessible online.

JVM
GitHub stars5
Dependents0
Creation datealmost 6 years ago

Last activity11 months ago
Latest release0.3.0-alpha.1 (almost 2 years ago)

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")
JVM
GitHub stars5
Dependents0
Creation datealmost 6 years ago

Last activity11 months ago
Latest release0.3.0-alpha.1 (almost 2 years ago)

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")