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.
- 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
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;
}
}
public interface ServiceInterface {
String BASE_URL = "https://run.mocky.io/v3/";
@GET("a0528e65-80c9-4172-9231-876a622f25ef")
Call<DataModel> getBooksList();
}
Try out the api from the website like provided below