October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Use HTTP_INTERCEPTORS in Angular

HTTP_INTERCEPTORS collects class-based Angular interceptors, but standalone HttpClient must opt in with withInterceptorsFromDi(). For new code, Angular recommends functional interceptors with an explicit ordered list.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

HTTP_INTERCEPTORS is Angular’s dependency-injection token for registering class-based HTTP interceptors as a multi-provider array. With standalone provideHttpClient, registration alone is not enough: enable those interceptors with withInterceptorsFromDi(). For new code, Angular recommends functional interceptors registered with withInterceptors([...]), which also makes their order explicit.

What HTTP_INTERCEPTORS does

HTTP_INTERCEPTORS is an Angular injection token that collects class-based HttpInterceptor instances. A multi-provider lets multiple interceptors contribute to the same token rather than replacing one another. An interceptor can inspect or modify an outgoing request and observe or transform the response as it passes through the HTTP pipeline.

As an Amazon Associate I earn from qualifying purchases.

Common patterns include adding authentication headers, retrying failures, caching, logging or measuring response times, showing loading indicators, and applying timeouts. These are options for cross-cutting HTTP behavior, not requirements for every application. See Angular’s HTTP_INTERCEPTORS API and interceptor guide.

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

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:

import { bootstrapApplication } from '@angular/platform-browser';
import {
  HTTP_INTERCEPTORS,
  provideHttpClient,
  withInterceptorsFromDi,
} from '@angular/common/http';

bootstrapApplication(App, {
  providers: [
    provideHttpClient(withInterceptorsFromDi()),
    { provide: HTTP_INTERCEPTORS, useClass: LoggingInterceptor, multi: true },
  ],
});

The two configuration parts have separate jobs: the provider adds the class to the token’s multi-provider array, while withInterceptorsFromDi() tells this HttpClient configuration to read class-based interceptors from dependency injection. Without the feature, adding the token provider by itself does not enable the interceptor in this setup. Angular documents this feature in the withInterceptorsFromDi API and its HttpClient setup guide.

Use functional interceptors for new code

Angular recommends functional interceptors for new applications. Register them directly with withInterceptors:

provideHttpClient(
  withInterceptors([loggingInterceptor, cachingInterceptor])
)

The array is an explicit ordered list: the first interceptor is first in the request chain. This is easier to inspect than relying on provider ordering across a complex hierarchy of injectors. Angular’s interceptor guide recommends the functional approach for more predictable behavior in complex setups; the withInterceptors API documents the registration method.

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

Class-based versus functional registration

Approach Registration Enablement Order Angular guidance
Class-based HTTP_INTERCEPTORS provider with multi: true In standalone provideHttpClient configuration, also use withInterceptorsFromDi() Depends on provider and injector configuration; can be harder to reason about in extensive hierarchies Supported, but Angular says DI-provided interceptors may be phased out in a later release; no dated removal schedule is stated
Functional withInterceptors([interceptorA, interceptorB]) Configured as part of provideHttpClient Explicit order in the array Recommended by Angular for new code

The possible future phase-out mentioned in the withInterceptorsFromDi API reference is not a scheduled removal. The reference does not give a date.

Change requests without mutating them

HTTP requests and responses are generally immutable. To adjust a request—such as adding a header—create a clone with the change rather than modifying the original request object. Be especially cautious about mutating a request’s body: bodies can contain mutable data, and a retry may run the interceptor again, making a deep mutation occur more than once. Angular covers cloning and interceptor behavior in its interceptor guide.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot an interceptor that does not run

  • Standalone class-based setup: Confirm that the active provideHttpClient configuration includes withInterceptorsFromDi().
  • Provider registration: Confirm the class is provided under HTTP_INTERCEPTORS and that the provider uses multi: true.
  • Client and injector: Check that the request uses the HttpClient configured with the interceptor feature and that the provider is in the injector visible to that client.
  • Ordering: If several interceptors interact, inspect their order. For a functional setup, the withInterceptors([...]) array makes the intended sequence visible.

For setup details, consult Angular’s HttpClient setup guide. Angular also provides an interceptor CLI generator for creating interceptor scaffolding.

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.