Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AhmedOmarDarwish/773f536e1d2de7da5a1a012cd6b474f2 to your computer and use it in GitHub Desktop.
Save AhmedOmarDarwish/773f536e1d2de7da5a1a012cd6b474f2 to your computer and use it in GitHub Desktop.
son gson = new GsonBuilder().serializeNulls().create();
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request originalRequest = chain.request();
Request newRequest = originalRequest.newBuilder()
.header("Interceptor-Header", "xyz")
.build();
return chain.proceed(newRequest);
}
})
.addInterceptor(loggingInterceptor)
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://jsonplaceholder.typicode.com/")
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build();
jsonPlaceHolderApi = retrofit.create(JsonPlaceHolderApi.class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment