Interceptors - don't repeat yourself

How to solve repetition problem in HTTP clients
One of my colleagues opened the following MR.

The first thing that catches the eye is the most common programming smell - repetition.

One way to handle it is to move the repetition into a separate method.

And call it in each of the get methods.

But again - repetition. Each new method still has duplicated code.

The solution here is to use an interceptor.
An interceptor allows you to modify a request before it's executed or a response before it's returned.
To solve the repetition problem, we'll use the request interceptor.
We'll move the authorisation logic to an interceptor.

Now we can remove the repetition from the client.

Et vuala. No more repetition.
Interceptors have many use cases. Based on my experience, setting a header is the most common one.
Other common use cases are:
- Logging request/response
- Retrying a request on error with a backoff strategy
- Error mapping