Interceptors in Angular — Adding custom headers in all http request.
Intercepting requests and responses
From Angualr Docs
“With interception, you declare interceptors that inspect and transform HTTP requests from your application to a server. The same interceptors can also inspect and transform a server’s responses on their way back to the application. Multiple interceptors form a forward-and-backward chain of request/response handlers. Interceptors can perform a variety of implicit tasks, from authentication to logging, in a routine, standard way, for every HTTP request/response. Without interception, developers would have to implement these tasks explicitly for each HttpClient method call.”
Multiple interceptors
Example : Adding custom headers in all http request.
Example code on github
Run the code in stackblitz
File Structure:
Code:
Output:
The header will be added in all http request.