OkHttp & Interceptors
DATA › Networking
Configuring OkHttp and using interceptors for auth, logging, caching, and TLS.
OkHttp is the de facto HTTP stack on Android and the engine under Retrofit, so interviewers probe how you configure a client and where you hook into the request/response pipeline. Expect to explain the application-vs-network interceptor distinction, how to inject auth tokens, and how caching, timeouts, connection pooling, and certificate pinning are tuned. Getting the interceptor execution model and OkHttpClient sharing right separates seniors from juniors.
What this covers
- Application vs network interceptors: ordering, how many times each runs, and what each can see
- Injecting auth headers/tokens and refreshing them via interceptors or Authenticator
- Adding HttpLoggingInterceptor and choosing the right log level for prod vs debug
- Configuring response caching, timeouts, and the connection pool / keep-alive
- Certificate pinning with CertificatePinner and why it belongs on network traffic
- Transparent gzip behavior and when manual Content-Encoding handling is needed
Study this topic
- OkHttp & Interceptors explained: the guided lesson
- 14 practice quiz questions
- 9 revision flashcards
- OkHttp & Interceptors interview questions and answers