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 |
JVM11+
- Add it to your retrofit builder:
var retrofit=new Retrofit.Builder()
.baseUrl(...)
.addConverterFactory(...)
.addCallAdapterFactory(new CallXAdapterFactory())
.build();
- Define your API return type with
CallX
instead ofCall
interface APIs {
@GET("posts")
CallX<List<Post>> getPosts();
}
- Use it in your API call:
api.enqueue((call,response)->{
//handle response
},(call,error)->{
//handle error
});
Find the latest version from Maven Artifact
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'
}
Add the dependency
<dependency>
<groupId>io.github.yamin8000</groupId>
<artifactId>yarca</artifactId>
<version>$last_version</version>
<type>aar</type>
</dependency>
dependencies {
implementation("io.github.yamin8000:yarca:$last_version")
}
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 |
- 1.0.0 - Initial release
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.