OkHttp Interceptors in Android

May 25 2021 · Kotlin 1.4, Android 5, Android Studio 4.1

Part 1: Implementing OkHttp Interceptors

03. Setup HttpLoggingInterceptor & Debug API Calls

Episode complete

Play next episode

About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 02. Set Up the Project Next episode: 04. Implement a Custom Logger & Redact Headers

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

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

HttpLoggingInterceptor is an Interceptor that lets you log all the API requests made by your app as well as the responses returned by the server.

implementation “com.squareup.okhttp3:logging-interceptor:4.9.0”`
fun getOkHttpClient(): OkHttpClient {
    return if (okHttpClient == null) {
        val okHttpClient = OkHttpClient.Builder()
            .readTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS)
            .connectTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS)
        OkHttpProvider.okHttpClient = okHttpClient
    } else {
val loggingInterceptor = HttpLoggingInterceptor()
loggingInterceptor.level = HttpLoggingInterceptor.Level.BASIC
val okHttpClient = OkHttpClient.Builder()
    .readTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS)
    .connectTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS)
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
fun getMovieDetails(@Path("id") id: Long, @Query("api_key") api_key: String = BuildConfig.THE_MOVIE_DB_API_TOKEN): Call<MovieDetailsModel>