I am using Retrofit-2.0.0
for my app. Now every tutorial on Retrofit I found on web is based on earlier Retrofit
and there was no Call
Use an Interceptor from OkHttp On Retrofit 1.9 you could use RequestInterceptor to intercept a Request but it is already removed on Retrofit 2.0 since the HTTP connection layer has been moved to OkHttp.
As a result, we have to switch to an Interceptor from OkHttp from now on. First you have to add it to build.gradle
compile 'com.squareup.okhttp:okhttp:2.5.0'
and then create a OkHttpClient object with an Interceptor like this:
OkHttpClient client = new OkHttpClient();
client.interceptors().add(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response response = chain.proceed(chain.request());
// Do anything with response here
return response;
}
});
And then pass the created client into Retrofit's Builder chain.
Retrofit retrofit = new Retrofit.Builder().baseUrl("http://api.themoviedb.org/3/discover/").addConverterFactory(GsonConverterFactory.create()).client(client).build();
Remove '/' from your @GET("/abc") because Retrofit 2.0 comes with new URL resolving concept. Base URL and @Url have not just simply been combined together but have been resolved the same way as what does instead. Please take a look for the examples below for the clarification.
To know more about Retrofit 2.0