Get immediate access to this and over 1,500+ other videos and books.

Boost your skills with a Beginner subscription. With over 60+ video courses and our core foundational programming books bundled in one subscription, it’s simply the best investment you can make in your development career.

Build Retrofit Components

The student materials have been reviewed and are updated as of July 2022.

Build the OkHttpClient, Retrofit and the RemoteApiService instance, to prepare everything for API call implementation.


Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a Professional subscription.

As you’ve learned, to use Retrofit, you need to first build a Retrofit client, providing the Base URL, and other configuration you might need. Let’s see how to do that!

implementation 'com.squareup.retrofit2:retrofit:2.7.2'
compileOptions {
  sourceCompatibility JavaVersion.VERSION_1_8
  targetCompatibility JavaVersion.VERSION_1_8
fun buildClient(): OkHttpClient = 
fun buildRetrofit(): Retrofit {
  return Retrofit.Builder()
interface RemoteApiService {
fun buildApiService(): RemoteApiService = 
class RemoteApi(private val apiService: RemoteApiService) {
private val apiService by lazy { buildApiService() }

val remoteApi by lazy { RemoteApi(apiService) }