How to use interceptor to add Headers and body in Retrofit 2.0

Updated 4 August 2017

Save

Interceptor the team sounds like something which is used in between the source and destination. In another language, an interceptor can hijack HTTP requests before they reach the endpoint.

By the Wikipedia,

In the field of software development, an interceptor pattern is a software design pattern that is used when software systems or frameworks want to offer a way to change, or augment, their usual processing cycle. Key aspects of the pattern are that the change is transparent and used automatically. In essence, the rest of the system does not have to know something has been added or changed and can keep working as before. To facilitate this, a predefined interface for extension has to be implemented, some kind of dispatching mechanism is required where interceptors are registered (this may be dynamic, at runtime, or static, e.g. through configuration files) and context objects are provided, which allow access to the framework’s internal state.

 

How to add the interceptor in Retrofit2.0 android

Step 1: Create a retrofit client,

 

Step 2: Create interceptor,

Step 3: Add interceptor,

Step 4: Add to the retrofit client,

 

Thanks for reading this blog, You have any questions or problems comment below.

Happy Coding. Stay Super.

 

 

 

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project


    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home