An tool to help developer to use Retrofit elegantly while using kotlinx.coroutines.

Overview

one

An tool to help developer to use Retrofit elegantly while using kotlinx.coroutines.

Feature

  1. Transform different data structs to one.
    • {errorCode, data, messsage}, {status, data, messsage} etc to one like {code, data, message}.
  2. No try catch needed when call a suspend method.
    • try catch has been processed by reproxy interface.

Example

// call `proxyRetrofit` after `Retrofit#create`, in this method it will handle
// exception automatically.
val service = retrofit.create(WanAndroidService::class.java).proxyRetrofit()
// test
service.test()
	.onSuccess { println("execute test success ==> $it") }
	.onFailure { println("execute test() failure ==> $it") }
	// userInfo
	.onFailureThen { service.userInfo() }
	?.onSuccess { println("execute userInfo success ==> $it") }
	?.onFailure { println("execute userInfo() failure ==> $it") }
	// banner
	?.onFailureThen { service.banner() }
	?.onSuccess { println("execute banner() success ==> $it") }
	?.onFailure { println("execute banner() failure ==> $it") }

Is that realy simple and clean without try catch? If so, continuate to read following sections.

Usage

  1. Define a BaseAPIResult.
  2. Define a ThrowableResolver to handle throwable and return a BaseAPIRsult which contains failure.
  3. Define a ResponseThransformer to transfrom different response data struct to the same response data struct.
  4. Add TansformConverterFactory to Retrofit Converter.Factory list at first.
  5. Call proxyRetrofit after calling Retrofit#create.

Read OneTest to understand details.

About the one

Why the repository is named one, just because I cannot figure how to name it.

License

Copyright 2021 ParadiseHell.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
CSV and FixedLength Formats for kotlinx-serialization

Module kotlinx-serialization-csv Serialize and deserialize ordered CSV and Fixed Length Format Files with kotlinx-serialization. Source code Docs Inst

Kotlin tooling for generating kotlinx.serialization serializers for serializing a class as a bitmask

kotlinx-serialization-bitmask Kotlin tooling for generating kotlinx.serialization serializers for serializing a class as a bitmask. Example @Serializa

KotlinX Serialization Standard Serializers (KS3)

KotlinX Serialization Standard Serializers (KS3) This project aims to provide a set of serializers for common types. ⚠️ Consider this project to be Al

 Movie app that receives popular movies and allows the user to search for the specific movie through the Rest API with help of retrofit library &MVVM architecture.
Movie app that receives popular movies and allows the user to search for the specific movie through the Rest API with help of retrofit library &MVVM architecture.

MovieClue Millions of movies, TV shows and people to discover. Explore now Movie app that recieves popular movies and allow the user to search for spe

Android News Reader app. Kotlin Coroutines, Retrofit and Realm
Android News Reader app. Kotlin Coroutines, Retrofit and Realm

News Reader Android News Reader app Code that follows Packt Publishing Kotlin in Practice Video Course Example of Kotlin Coroutine usage, with Realm a

Includes jetpack compose, navigation, paging, hilt, retrofit, coil, coroutines, flow..
Includes jetpack compose, navigation, paging, hilt, retrofit, coil, coroutines, flow..

Nextflix-Composable A Clean Architecture App to show use of multi-module-architecture in a Jetpack Compose. The modules are as follow: app: Presentati

Educational App made with Retrofit, Coroutines, Navigation Component, Room, Dagger Hilt, Flow & Material Motion Animations.
Educational App made with Retrofit, Coroutines, Navigation Component, Room, Dagger Hilt, Flow & Material Motion Animations.

TechHub TechHub is a sample educational app that provides courses for people who want to learn new skills in mostly tech-related areas. The goal of th

E-Commerce application with MVVM & Clean Arch - Hilt - Coroutines - Retrofit - Firebase - Room DB.
E-Commerce application with MVVM & Clean Arch - Hilt - Coroutines - Retrofit - Firebase - Room DB.

E-Commerce-App E-Commerce application with MVVM & Clean Arch - Hilt - Coroutines - Retrofit - Firebase - Room DB. API Link Project Features MVVM with

A Lightweight PDF Viewer Android library which only occupies around 125kb while most of the Pdf viewer occupies up to 16MB space.
A Lightweight PDF Viewer Android library which only occupies around 125kb while most of the Pdf viewer occupies up to 16MB space.

Pdf Viewer For Android A Simple PDF Viewer library which only occupies around 125kb while most of the Pdf viewer occupies upto 16MB space. How to inte

Comments
  • FakeSuccessContinuationWrapper的调度问题

    FakeSuccessContinuationWrapper的调度问题

    #1 throwableResolver.resolve()看起来只是构建异常结果,在构建FakeSuccessContinuationWrapper时,传入拦截后的Continuation,解决resumeWith()的调度问题或许会更好。

    import kotlin.coroutines.intrinsics.intercepted
    
    FakeSuccessContinuationWrapper(
        (args.last() as Continuation<Any>).intercepted(),
        resolver as ThrowableResolver<Any>
     )
    
    good first issue 
    opened by xiaocydx 8
Owner
ChengTao
Know the unknown.
ChengTao
Small Kafka Playground to play around with Test Containers, and KotlinX Coroutines bindings while reading Kafka Definite Guide V2

KafkaPlayground Small playground where I'm playing around with Kafka in Kotlin and the Kafka SDK whilst reading the Kafka book Definite Guide from Con

Simon Vergauwen 34 Dec 30, 2022
Automatic CoroutineDispatcher injection and extensions for kotlinx.coroutines

Dispatch Utilities for kotlinx.coroutines which make them type-safe, easier to test, and more expressive. Use the predefined types and factories or de

Rick Busarow 132 Dec 9, 2022
Kotlinx-murmurhash - Kotlin Multiplatform (KMP) library for hashing using MurmurHash

kotlinx-murmurhash Kotlin Multiplatform (KMP) library for MurmurHash, a non-cryp

Gonçalo Silva 23 Dec 27, 2022
Type-safe arguments for JetPack Navigation Compose using Kotlinx.Serialization

Navigation Compose Typed Compile-time type-safe arguments for JetPack Navigation Compose library. Based on KotlinX.Serialization. Major features: Comp

Kiwi.com 32 Jan 4, 2023
Architecture With MVI using Kotlin, Coroutines, Retrofit and Unit test

Architecture With MVI using Kotlin, Coroutines, Retrofit and Unit test MVI (Model-View-Intent) streamlines the process of creating and developing appl

Ahmed Karam 4 Aug 18, 2022
Recycler-coroutines - RecyclerView Auto Add Data Using Coroutines

Sample RecyclerView Auto Add With Coroutine Colaborator Very open to anyone, I'l

Faisal Amir 8 Dec 1, 2022
This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture.

Clean-architecture This Project for how to use MVVM , state flow, Retrofit, dagger hit, coroutine , use cases with Clean architecture. Why i should us

Kareem Aboelatta 10 Dec 13, 2022
Android Bundle format support for Kotlinx Serialization.

Bundlizer Android Bundle format support for Kotlinx Serialization. Usage Annotate your data models with @Serializable: import kotlinx.serialization.Se

Ahmed Mourad 69 Nov 9, 2022
Minecraft NBT support for kotlinx.serialization

knbt An implementation of Minecraft's NBT format for kotlinx.serialization. Technical information about NBT can be found here. Using the same version

Ben Woodworth 41 Dec 21, 2022
Android Parcelable support for the Kotlinx Serialization library.

Android Parcelable support for the Kotlinx Serialization library.

Christopher 50 Nov 20, 2022