Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 2.17 KB

File metadata and controls

59 lines (42 loc) · 2.17 KB

Android Retrofit Example platform license Build status

Retrofit Example App implements the Retrofit2 dependency in Android to make API calls GET requests. Retrofit2 makes the whole task of calling APIs and parsing responses super easy with almost everything at your disposal. This demo app uses a public Book Description API to demonstrate the usage.

Activites

  • Splash
  • MainActivity with recycler view to fetch and display data from the API
  • BookDetails activity to display all the information w.r.t a selected book

Retrofit Helper

public class RetrofitHelper {

        private static RetrofitHelper instance = null;
        private final ServiceInterface serviceInterface;

        private RetrofitHelper() {
            Retrofit retrofit = new Retrofit.Builder().baseUrl(ServiceInterface.BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            serviceInterface = retrofit.create(ServiceInterface.class);
        }

        public static synchronized RetrofitHelper getInstance() {
            if (instance == null) {
                instance = new RetrofitHelper();
            }
            return instance;
        }

        public ServiceInterface getServiceInterface() {
            return serviceInterface;
        }
    }

Network Service Interface

public interface ServiceInterface {

    String BASE_URL = "https://run.mocky.io/v3/";

    @GET("a0528e65-80c9-4172-9231-876a622f25ef")
    Call<DataModel> getBooksList();
}

API

Try out the api from the website like provided below

https://designer.mocky.io/

License