This library provides an easy to use wrapper for Retrofit library to make network calls
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Basic features:

  • Provides out of the box network check and error handling
  • Show progress view while making network calls
  • Multiple methods for initializing Retrofit services


   compile 'in.ashwanik:retro-client:0.1.2'


Initialize RetroClient using RetroClientServiceInitializer in an activity or Application class

            progressViewColor = getResources().getColor(R.color.colorPrimary, null);
        } else {
            progressViewColor = getResources().getColor(R.color.colorPrimary);
        RetroClientServiceInitializer.getInstance().initialize(ApiUrls.BASE_API_URL, getApplicationContext(), progressViewColor, true);

Add interceptor

  List<Interceptor> interceptors = new ArrayList<>();
        interceptors.add(new Interceptor() {
            public Response intercept(Chain chain) throws IOException {
                Request request = chain.request();
                Response response = chain.proceed(request);
                Helpers.d(RetroClientServiceInitializer.getInstance().getLogCategoryName(), response.code() + "");
                return response;
                .initialize(ApiUrls.BASE_API_URL, progressViewColor, true, 10 * 1024 * 1024, getCacheDir(), interceptors, null);

Define a client

public interface BookClient {
    Call<Book> get(@Path("bookId") Integer bookId);

    Call<List<Book>> get();

    Call<Book> create(@Body Book book);

    Call<Book> update(@Body Book book, @Path("bookId") Integer bookId);

    Call<Void> delete(@Path("bookId") Integer bookId);

Make the call

RetroClientServiceGenerator serviceGenerator = new RetroClientServiceGenerator(MainActivityFragment.this.getActivity(), false);
        BookClient client = serviceGenerator.getService(BookClient.class);
        serviceGenerator.execute(client.get(1), new RequestHandler<Book>() {
            public void onSuccess(Book response) {
                  Log.d("RetrofitSample", response.toString());

            public void onError(ErrorData errorData) {
                Log.d("RetrofitSample", errorData.toString());

Options for RetroClientServiceInitializer

  • baseUrl: Base Url for API
  • converterFactory: Set converter factory. Default is JSON
  • timeOut: Timeout (seconds) for network calls. Default is 30
  • enableRetry: Enable request retry. Default true
  • isDebug: Enabling debugging. Level.BODY is used for logging. Default is false
  • logCategoryName: Log category
  • progressViewColor: Specify the color of progress view
  • logger: Logger used for logging exception etc to external services like Crashlytics.
  • cacheDirectory: Pass location of cache directory.
  • cacheSize: Size of cache.

Sample app is available here

Sample rest API using Node.js is available here


  • Released 0.1.2 version

    • Updated Retrofit version
    • Fixed issues
    • Added support for adding network and application level interceptors
  • Released 0.1.1 version

    • Updated Retrofit version
    • Added support for changing default messages
    • Added support for changing cache directory
    • Added support for changing cache directory size
    • Code refactoring
  • Released 0.1.0 version


  1. Nice code for circular progress view
  2. Retrofit Examples
  3. Tutorials on Retrofit by FutureStud

For more tutorials on Android, please check here.