Read complete story

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

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.

 

 

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close