Easy.Api is a bundle of utility classes which helps to call the RESTful webservices as quickly as never before. It also allows use of RxJava with only fewer implementation detail. It also works with kotlin.
It is just a wrapper utility class over retrofit call, which provides you ability to write concise and less lines of code with flexibility of changing loading and error handling behavior as per your need on specific screens of your application
I. Network connectivity check
II. Loading behavior
III. Error handling
IV. Success/failure check
Let's see it in action ๐ป๐ฒ
- Default request:
new EasyApi<Envelop<List<User>>>(Objects.requireNonNull(getActivity()))
.setLoaderInterface(this)
.initCall(ApiFactory.getInstance().fetchUsers("1"))
.execute((response, isSuccess, successMessage) -> {
if (isSuccess) {
adapter.setUserList(response.getData());
}
});
- With RxJava:
DisposableObserver<?> d = new EasyApiRx<Envelop<List<User>>>(Objects.requireNonNull(getActivity()))
.setLoaderInterface(this)
.initCall(ApiFactory.getInstance().fetchUsersWithRx("1"))
.execute((response, isSuccess, message) -> {
if (isSuccess) {
adapter.setUserList(response.getData());
}
});
disposable.add(d);
- In Kotlin:
EasyApi<Envelop<List<User>>>(Objects.requireNonNull<FragmentActivity>(activity))
.setLoaderInterface(this)
.initCall(ApiFactory.instance!!.fetchUsers("1"))
.execute { response, isSuccess, _ ->
if (isSuccess) {
adapter?.setUserList(response.data!!)
}
}
- In Kotlin with Rx:
val d = EasyApiRx<Envelop<List<User>>>(Objects.requireNonNull<FragmentActivity>(activity))
.setLoaderInterface(this)
.initCall(ApiFactory.instance!!.fetchUsersWithRx("1"))
.execute { response, isSuccess, _ ->
if (isSuccess) {
adapter?.setUserList(response.data!!)
}
}
disposable!!.add(d!!)