Skip to content

Instantly share code, notes, and snippets.

@AkshayMoorthy
Created April 26, 2018 08:58
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 AkshayMoorthy/dc9b6c3230e55cb35f6fb275960141f7 to your computer and use it in GitHub Desktop.
Save AkshayMoorthy/dc9b6c3230e55cb35f6fb275960141f7 to your computer and use it in GitHub Desktop.
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
//Create a new Interceptor.
Interceptor headerAuthorizationInterceptor = new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
okhttp3.Request request = chain.request();
Headers headers = request.headers().newBuilder().add("Authorization", authToken).build();
request = request.newBuilder().headers(headers).build();
return chain.proceed(request);
}
};
//Add the interceptor to the client builder.
clientBuilder.addInterceptor(headerAuthorizationInterceptor);
return new Retrofit.Builder().baseUrl(ROOT_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment