Last active
April 3, 2018 01:55
-
-
Save nishantkp/2c05d4ec8ae1af42f8e3468927246515 to your computer and use it in GitHub Desktop.
ApiClient for retrofit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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