Sometimes you will need to add the same header or change something about every request being made. Instead of including it in every single method definition, it is much easier to define a custom OkHttp intercept to handle it for you.
- [Instructor] We have authorized the one call…to get user details…and now, we need to authorize all of the other calls…that we make.…Doing this for every method definition, though,…can be rather tedious and will require you to provide…an authorization header as a parameter in every single one.…Instead, we can make this easier…by adding it to every request…using an OkHttp request interceptor.…The implementation of the service interface…that the Retrofit API creates for us…is built using the OkHttp client,…which is also developed by Square,…the team that developed Retrofit.…
We can override the default client…used to include an interceptor to modify the request…before it is executed.…To do this, we need to add the OkHttp package…as a dependency.…Just like the Retrofit package,…you can find the Gradle dependency line…for the OkHttp package on their website,…which is usually at square.github.io/okhttp.…In the Download section,…you can find the Gradle and Maven dependency code.…
I'm going to copy the Gradle implementation line.…
- REST API basics
- Methods for reading and writing data
- Defining data models with Retrofit
- Implementing an API interface
- Getting data with a Retrofit call
- Authorizing requests
- Putting, deleting, and posting data
- Customizing the data converter
- Working with the request and response headers
Skill Level Intermediate
Android App Development: Enterprise Integrationwith Jon-Luke West47m 51s Intermediate
Android App Development: Data Persistence Librarieswith Annyce Davis4h 52m Intermediate
1. HTTP APIs
2. Get Started with Retrofit
3. Finish the Sample App
4. More Configuration Options
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.