Advertisement
romaiswara

api client java

Jan 23rd, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. public class APIClient {
  2. private static volatile APIClient instance = null;
  3. private Retrofit retrofit;
  4.  
  5. public APIClient() {
  6. OkHttpClient okHttpClient = new OkHttpClient.Builder()
  7. .addNetworkInterceptor(new StethoInterceptor())
  8. .build();
  9.  
  10. retrofit = new Retrofit.Builder()
  11. .baseUrl(Constant.BASE_URL)
  12. .addConverterFactory(GsonConverterFactory.create())
  13. .client(okHttpClient)
  14. .build();
  15. }
  16.  
  17. public static APIClient getInstance() {
  18. if (instance == null) {
  19. synchronized (APIClient.class){
  20. instance = new APIClient();
  21. }
  22. }
  23. return instance;
  24. }
  25.  
  26. public MovieService getApi(){
  27. return retrofit.create(MovieService.class);
  28. }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement