Created
May 30, 2019 19:26
-
-
Save AhmedOmarDarwish/773f536e1d2de7da5a1a012cd6b474f2 to your computer and use it in GitHub Desktop.
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
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