#How can I use add an header to an Axios instnace just for one specific module ?
8 messages · Page 1 of 1 (latest)
If you're importing HttpModule.register in each module, then each module has its own copy of HttpService and axios. So you can just configure HttpModule differently in that particular module
I was not clear. sorry.
The goal is that every module will have the same axios instance since i have common interceptors for this axios.
But if some module would like to add a common header or other specific configuration , is it possible to do it for just a specific module ?
(I have a certain module that need to send some specific header in all of his external calls)
Interceptors inject providers from the module that they're used in. That means if you configure the HttpModule in one module diffferently, ypur interceptor will inject the HttpService from the module.
ok, but how can I use the same http module (shared http module) with some common interceptors, and in one specific module to have the same interceptors but also have a specific header for all of its external requests ?
Instead of just add that header on each axios call.
Is it possible at all if configuring a http module (by forRoot or regsiter) creates a new axios instance ?
by interceptors do you mean Nest interceptors or Axios interceptorys?
Axios interceptors
Ah, I see. Well, axios interceptors are bound to a specific instance of axios (and therefore HttpService). So what you can do is configure your common HttpModule in some wrapper module, re-export it, and import the wrapper module anywhere that the common functionaliy is needed. In modules where a different functionality is needed, configure a new HttpModule