Android Retrofit Design Patterns

I usually use singleton pattern with following structure :

first define ServiceHelper like following :

public class ServiceHelper {

private static final String ENDPOINT = "";

private static OkHttpClient httpClient = new OkHttpClient();
private static ServiceHelper instance = new ServiceHelper();
private IPlusService service;

private ServiceHelper() {

    Retrofit retrofit = createAdapter().build();
    service = retrofit.create(IPlusService.class);

public static ServiceHelper getInstance() {
    return instance;

private Retrofit.Builder createAdapter() {

    httpClient.setReadTimeout(60, TimeUnit.SECONDS);
    httpClient.setConnectTimeout(60, TimeUnit.SECONDS);
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();

    return new Retrofit.Builder()

public Call<List<CategoryModel>> getAllCategory() {
    return service.getAllCategory();

Then put all of your services in IService (in my case it’s IPlusService)

    public interface IPlusService {
    //@Headers( "Content-Type: application/json" ) in Post method may use this
    Call<List<CategoryModel>> getAllCategory();

Then call your singleton like below in your activity/fragment :

ServiceHelper.getInstance().getAllCategory().enqueue(new Callback<List<CategoryModel>>() {
        public void onResponse(Response<List<CategoryModel>> response, Retrofit retrofit) {

        public void onFailure(Throwable t) {

Leave a Comment