O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Service factory

Let's start by creating a class--RetrofitYahooServiceFactory:

public class RetrofitYahooServiceFactory {}

Before we can make our first request, we will need to prepare an interceptor that we will use for logging:

public class RetrofitYahooServiceFactory {    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor()            .setLevel(HttpLoggingInterceptor.Level.BODY);}

It is advised to turn off logging for production applications to get better performance but, in our case, especially while we are learning, it is crucial to have appropriate logging so that we can see what is actually going on.

Afterward, the OkHttp client that the Retrofit will use, can be prepared:

OkHttpClient client = new OkHttpClient.Builder().addInterceptor( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required