OkHttp Interceptors in Android
Learn how to use OkHttp Interceptors to intercept network requests, log them and also modify them on the fly. By Subhrajyoti Sen.
Learning path
This is part of the Advanced Android Data & Networking learning path. View path.
Who is this for?
This course is for Android developers who want to monitor and modify network calls at the application and network levels, in turn simplifying network operations.
Covered concepts
- Initializing OkHttp Interceptors
- Choosing between Application and Network Interceptors
- Logging network data with different log levels
- Redacting sensitive information from network logs
- Debugging network errors
- Adding authentication token to all API calls
- Adding custom headers useful for analytics
Part 1: Implementing OkHttp Interceptors
Find out what OkHttp Interceptors are. Learn the difference between Application and Network Interceptors.
Generate a TheMovieDB API key and use it to get the starter project running.
Log and debug API calls by implementing a custom Interceptor. Learn about the different logging levels.
Use a custom logging client to control how the Interceptor logs the API calls and also redact sensitive information from the logs.
Implement an Interceptor that adds the API key to all API calls and avoid duplication of effort.
Learn how to implement an Interceptor to add custom headers that are useful for analytics.