Recall & Review
beginner
What is an OkHttp interceptor?
An OkHttp interceptor is a component that can observe, modify, and retry HTTP requests and responses in an OkHttp client.
Click to reveal answer
beginner
Name the two main types of OkHttp interceptors.
The two main types are Application Interceptors and Network Interceptors. Application interceptors work before the request is sent and after the response is received. Network interceptors work at the network level, just before the request is sent to the network and just after the response is received from the network.
Click to reveal answer
beginner
How do you add an interceptor to an OkHttpClient in Kotlin?
You add an interceptor by calling
addInterceptor() or addNetworkInterceptor() on the OkHttpClient.Builder before building the client.Click to reveal answer
beginner
What is a common use case for an OkHttp interceptor?
Common uses include adding headers like authentication tokens, logging request and response data, retrying requests, and modifying requests or responses.
Click to reveal answer
intermediate
What is the difference between
proceed(request) and modifying the request inside an interceptor?proceed(request) sends the request to the next interceptor or network. You can modify the request before calling proceed() to change headers or body.Click to reveal answer
Which method do you override to create a custom OkHttp interceptor?
✗ Incorrect
You override the intercept(chain: Interceptor.Chain) method to define how the interceptor processes requests and responses.
Where does a network interceptor operate in the request lifecycle?
✗ Incorrect
Network interceptors operate just before the request is sent to the network and can also observe the raw response.
Which OkHttpClient builder method adds an application interceptor?
✗ Incorrect
addInterceptor() adds an application interceptor that works on all requests and responses.
What happens if you don’t call proceed(request) inside an interceptor?
✗ Incorrect
Not calling proceed(request) stops the chain, so the request does not continue to the next interceptor or network.
Which of these is NOT a typical use of an OkHttp interceptor?
✗ Incorrect
Changing app theme colors is unrelated to network requests and not done by interceptors.
Explain how OkHttp interceptors can help add authentication tokens to every request.
Think about how you can change the request before it goes out.
You got /3 concepts.
Describe the difference between application interceptors and network interceptors in OkHttp.
Consider when each interceptor sees the request and response.
You got /3 concepts.