Skip to content

Instantly share code, notes, and snippets.

@Axrorxoja
Created December 6, 2023 06:27
Show Gist options
  • Save Axrorxoja/3697d6efcead852e6536905c7fad7a8a to your computer and use it in GitHub Desktop.
Save Axrorxoja/3697d6efcead852e6536905c7fad7a8a to your computer and use it in GitHub Desktop.
retrofit wrapper
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitWrapper {
private Retrofit retrofit;
private String baseUrl;
public RetrofitWrapper(String baseUrl) {
this.baseUrl = baseUrl;
this.retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public Retrofit getRetrofit() {
return retrofit;
}
public void recreateWithBaseUrl(String newBaseUrl) {
this.baseUrl = newBaseUrl;
this.retrofit = new Retrofit.Builder()
.baseUrl(newBaseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
// Add other methods as needed, like for creating service interfaces
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment