In this tutorial you will learn how to set headers for every request in Angular using HttpInterceptor.

Solution

Let’s say we want to send 3 headers : Content-Type, Accept and Accept-Language. To set headers for every request in Angular, we will create a class that implements HttpInterceptor.

HttpInterceptor

For Accept header, the value is only set if the caller doesn’t set it.

Adding the interceptor to app.module.ts

Once the interceptor is created, we need to declare it in providers of our app.module.ts like below :

That’s it, your headers will be sent for every request.

References