Skip to content

Persist on the network (with Retrofit)

xcesco edited this page May 4, 2018 · 2 revisions

There are many libraries that permit to generate REST service client easily. The one that I prefer is Retrofit.

So, I decide to integrate Kripton with Retrofit, just to use Kripton persistence mechanism in Retrofit library. I want to show you here how simple is to work with them.

For example, we want to consume the REST service at

https://jsonplaceholder.typicode.com/posts/

So we define a Post class with Kripton BindType annotation

@BindType
public class Post {
  public long userId;
  public long id;
  public String title;
  public String body;
}

We can define the REST client interface:

public interface JsonPlaceHolderService {
  @POST("/posts/")
  Call<List<Post>> getAllPost();
}

The code to consume the REST service is:

// create retrofit using Kripton converter factory
Retrofit retrofit = new Retrofit.Builder()
  .baseUrl(“https://jsonplaceholder.typicode.com/")
  .addConverterFactory(KriptonBinderConverterFactory.create())
  .build();
JsonPlaceHolderService service = Retrofit.create(JsonPlaceHolderService.class);
// consume service
Response<List<Post>> response = service.getAllPost().execute();

The integration between Kripton and Retrofit is done by KriptonBinderConverterFactoryconverter.

Table of Contents

Query definition

Features

Relations

Multithread supports

Modularization

Annotations for data convertion

Annotations for SQLite ORM

Annotations for shared preferences

Clone this wiki locally