Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.

yamin8000/yarca

Repository files navigation

yarca or Yet Another Retrofit Call Adapter

yarca is an opinionated retrofit call adapter. it's the result of multiple iterations of custom retrofit call adapters that I used in various personal projects.

The fundamental difference between this call adapter and the default retrofit call adapter is that this adapter's callbacks use Java lambda expressions instead of default unpleasant anonymous class callbacks. This library provides multiple ways to handle response and error using various callbacks.


Icon Item
📺 Preview
📱 Compatibility
💻 Usage
📩 Download
📋 Features
🧾 Changelog
⚖️ License

Preview

preview

Compatibility

JVM11+

Usage

  1. Add it to your retrofit builder:
var retrofit=new Retrofit.Builder()
        .baseUrl(...)
        .addConverterFactory(...)
        .addCallAdapterFactory(new CallXAdapterFactory())
        .build();
  1. Define your API return type with CallX instead of Call
interface APIs {

    @GET("posts")
    CallX<List<Post>> getPosts();
}
  1. Use it in your API call:
api.enqueue((call,response)->{
            //handle response
        },(call,error)->{
            //handle error
        });

Download

Find the latest version from Maven Artifact

Gradle Groovy DSL

Step 1. Add the Maven repository to your build file
Add it in your root build.gradle at the end of repositories:

repositories {
    mavenCentral()
}

Step 2. Add the dependency

dependencies {
    implementation 'com.github.yamin8000:yarca:$last_version'
}

Maven

Add the dependency

<dependency>
    <groupId>io.github.yamin8000</groupId>
    <artifactId>yarca</artifactId>
    <version>$last_version</version>
    <type>aar</type>
</dependency>  

Gradle Kotlin DSL

dependencies {
    implementation("io.github.yamin8000:yarca:$last_version")
}

Features

There are different methods and callbacks, here is the table of some of them:

Type Description Code Example
enqueue A lambda wrapper around default enqueue method
api.enqueue((call,response)->{
    //handle response
}, (call,error)->{
    //handle error
});
async General purpose async call method.
api.async((response, error) -> {
    //handle response and error
    boolean isShuttingDown = false;
    return isShuttingDown;
});
atomicAsync Calls async and automatically shuts down the client.

enqueueAsync Calls async and doesn't care whether to shut down the client or not.

asyncBody Calls async but returns response body instead of OkHttp's Response class

Changelog

  • 1.0.0 - Initial release

License

yarca is licensed under the GNU General Public License v3.0
Permissions of this strong copyleft license are conditioned on making
available complete source code of licensed works and modifications,
which include larger works using a licensed work, under the same
license. Copyright and license notices must be preserved. Contributors
provide an express grant of patent rights.