Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

HTTP_INTERCEPTORS is Angular’s dependency-injection token for registering class-based HTTP interceptors. With standalone provideHttpClient, registering the token is not enough: add withInterceptorsFromDi() to enable those interceptors. For new code, Angular recommends functional interceptors registered with withInterceptors([...]), which makes their order explicit.

What HTTP_INTERCEPTORS does

HTTP_INTERCEPTORS is a multi-provider token whose value is an array of class-based HttpInterceptor instances. Interceptors can inspect or modify outgoing requests and handle responses as they pass through the HTTP chain. Angular documents patterns including authentication headers, retries, caching, logging, loading indicators, deadlines, batching and polling; use them when an application needs that behavior, rather than adding middleware by default. See Angular’s HTTP_INTERCEPTORS API and interceptor guide.

Register a class-based interceptor with standalone HttpClient

In a standalone application, configure provideHttpClient with withInterceptorsFromDi(), then register each class under HTTP_INTERCEPTORS with multi: true:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
bootstrapApplication(App, {
  providers: [
    provideHttpClient(withInterceptorsFromDi()),
    { provide: HTTP_INTERCEPTORS, useClass: LoggingInterceptor, multi: true },
  ],
});

Why both registrations matter

  • multi: true adds the class to the token’s interceptor array instead of replacing the provider value.
  • withInterceptorsFromDi() tells the configured HttpClient to use class-based interceptors from the injector.
  • Without that feature in this standalone configuration, the token registration alone does not enable the interceptor.

Angular documents the feature in its withInterceptorsFromDi API and covers client configuration in Setting up HttpClient.

When to use functional interceptors instead

For new code, Angular recommends functional interceptors. Register them directly with withInterceptors:

provideHttpClient(withInterceptors([loggingInterceptor, cachingInterceptor]))

The list order determines the interceptor chain order. Angular says this explicit ordering is more predictable, particularly in complex injector setups where provider ordering can be harder to reason about. The withInterceptors API documents functional registration. Angular’s withInterceptorsFromDi API also says to prefer withInterceptors and notes DI-provided interceptor support may be phased out in a later release; it does not specify a removal date.

Class-based and functional registration compared

Approach How it is registered Standalone HttpClient configuration Order Angular guidance
Class-based HTTP_INTERCEPTORS provider with multi: true Add withInterceptorsFromDi() Provider order can be harder to follow in complex hierarchical injector setups Supported; Angular recommends functional interceptors for new code
Functional Pass interceptor functions to withInterceptors([...]) Configure the functions in the provideHttpClient feature list The array explicitly determines chain order Recommended for new code

Changing requests and handling retries safely

Angular’s request and response objects are generally immutable. To change a request—for example, to add a header—clone it and pass the clone onward rather than modifying the original request object. Take extra care with deep mutations to a request body: a retry can run the interceptor again, so a mutation may be applied more than once. Angular discusses immutability and interceptor behavior in its interceptor guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why an Angular HTTP interceptor may not run

  • Standalone client is missing the DI feature: if the class is registered under HTTP_INTERCEPTORS, ensure that the relevant provideHttpClient configuration includes withInterceptorsFromDi().
  • The provider is not multi: use multi: true so the class contributes to the interceptor array.
  • You registered a functional interceptor as a class provider, or vice versa: class-based interceptors use the token; functional interceptors belong in the withInterceptors([...]) list.
  • The ordering is unexpected: inspect the configured chain and injector setup. With functional interceptors, the order in the array is the chain order.

Angular’s interceptor CLI generator documents its interceptor-generation command and options.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.