Retrofit Interceptor Study - Experiments and Ready to use retrofit interceptors
https://github.com/square/okhttp/wiki/Interceptors
https://futurestud.io/tutorials/retrofit-2-manage-request-headers-in-okhttp-interceptor
-
OkHttp Client Builder
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
-
Attach interceptor to the client's builder
httpClientBuilder.addInterceptor(new YourInterceptorClass());
-
Build OkHttpCLient
OkHttpClient httpClient = httpClientBuilder.build();
-
Initialize Retrofit
Retrofit retrofit = getRetrofitBuilder().client(httpClient).build();
Note:
getRetrofitBuilder()
is your class which returns Retrofit.Builder.