Skip to content

Instantly share code, notes, and snippets.

@nishantkp
Last active April 3, 2018 01:55
Show Gist options
  • Save nishantkp/2c05d4ec8ae1af42f8e3468927246515 to your computer and use it in GitHub Desktop.
Save nishantkp/2c05d4ec8ae1af42f8e3468927246515 to your computer and use it in GitHub Desktop.
ApiClient for retrofit
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
/**
* Use this class if you're using retrofit to make API call
* and Gson converter factory
*/
public class ApiClient {
private static Retrofit retrofit = null;
public static Retrofit getClient() {
// Get the OkHttpClient
OkHttpClient client = new OkHttpClient.Builder().build();
// Create a retrofit object
retrofit = new Retrofit.Builder()
.baseUrl("Your base-url string")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build();
return retrofit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment