https://github.com/javiersegoviacordoba/network-either-kmp
https://github.com/javiersegoviacordoba/network-either-kmp
arrow arrow-kt functional-programming hacktoberfest kotlin kotlin-multiplatform ktor ktor-client multiplatform multiplatform-kotlin-library retrofit retrofit2
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/javiersegoviacordoba/network-either-kmp
- Owner: JavierSegoviaCordoba
- Created: 2020-12-19T16:06:03.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-10T22:17:22.000Z (7 months ago)
- Last Synced: 2024-10-11T10:16:44.278Z (7 months ago)
- Topics: arrow, arrow-kt, functional-programming, hacktoberfest, kotlin, kotlin-multiplatform, ktor, ktor-client, multiplatform, multiplatform-kotlin-library, retrofit, retrofit2
- Language: Kotlin
- Homepage: https://network-either-kmp.javiersc.com
- Size: 9.98 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README

[](https://repo1.maven.org/maven2/com/javiersc/network/network-either/)
[](https://oss.sonatype.org/content/repositories/snapshots/com/javiersc/network/network-either/)[](https://github.com/JavierSegoviaCordoba/network-either-kmp/tree/main)
[](https://sonarcloud.io/dashboard?id=com.javiersc.network:network-either)
[](https://sonarcloud.io/dashboard?id=com.javiersc.network:network-either)
[](https://sonarcloud.io/dashboard?id=com.javiersc.network:network-either)# Network Either
## Ktor
### Usage
```kotlin
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 = client.get("dog").body()
response.fold(
failure = { ... },
success = { ... },
)
```Check all available functions in the [
`NetworkEither` class](subprojects/network-either/common/main/kotlin/com/javiersc/network/either/NetworkEither.kt).Check [the tests](subprojects/network-either/common/test/kotlin/com/javiersc/network/either/KtorTest.kt)
for more examples.## Retrofit
### Usage
```kotlin
val retrofit =
Retrofit
.Builder()
.baseUrl("org.example.com")
.addCallAdapterFactory(NetworkEitherCallAdapterFactory())
.build()interface DogService {
@GET("dog")
suspend fun getDog(): NetworkEither
}val service: DogService = retrofit.create()
val response: NetworkEither = service.getDog()
response.fold(
failure = { ... },
success = { ... },
)
```Check [the tests](subprojects/network-either/jvm/test/kotlin/com/javiersc/network/either/RetrofitTest.kt)
for more examples.## Docs
All docs are available on the [`network-either-kmp` website](https://network-either-kmp.javiersc.com)
## Download from MavenCentral
- NetworkEither, pretty printing logger and ResourceEither mappers
```kotlin
implementation("com.javiersc.network:network-either:$version")
```