Request Interceptor - devrath/DroidKotlinCleanArchitecture GitHub Wiki

squirrel

What is Request Interceptor

  • It is a mechanism using which we can monitor, retry, modify an API request
  • When there an API request, we can monitor the request and perform some tasks
  • Interceptors are like security personnel in an office, They check each person(Request), arriving at the office, Then perform a security check, if it's an authorized person, they allow them to pass.

Representation of Interceptor

Some usages of interceptor

  • Monitor the API calls centrally.
  • Usually we add a logger for each API call, We can add a single central logger in the Interceptor that will log the details of each API request.
  • We can cache the data from a response.
  • We can intercept each response from the server, Get the error code of each response and do something for it. For example, If we have an event server that we are sending the logs, we can perform it here.
  • Adding the common headers at one place instead of adding them on each API request.
  • Refreshing the token in one place instead, that can be utilized by all the requests.
  • We can use Gzip for compress/decompress of data.