NG.VII · Angular 22 practice question

In Angular, both class-based interceptors (implementing `HttpInterceptor`) and functional interceptors (`HttpInterceptorFn`) can modify HTTP requests. If you need to add headers based on the outgoing `HttpRequest` in a functional Angular 22 context, which approach is the most idiomatic?

Choose one answer
Check answer and explanation

Correct answer: Using an `HttpInterceptorFn` that clones the `HttpRequest` (for example with `req.clone({ setHeaders: ... })`) and passes the clone to `next`.

Explanation

Functional interceptors (using `HttpInterceptorFn`) are designed to integrate directly into the functional nature of Angular's HTTP client pipeline. They allow developers to transform or inspect the outgoing `HttpRequest` and the subsequent `HttpEvent` stream using standard functional patterns (like combining with other RxJS operators), making them highly flexible for pipeline-aware modifications compared to a purely external RxJS `tap`.

Common trap

Option A and D both describe the traditional class-based approach. While A and D work, C describes the modern, idiomatic *functional* way that aligns with the context of comparing it to other functional pipeline modifications. Option B is too limited as it only works on a single observable stream and doesn't fit into the general interceptor architecture.

Source: Angular HTTP Interceptors Guide (Specific documentation on `HttpInterceptorFn` expected in Angular 22 docs) https://angular.dev/guide/http/interceptors
Checked against the cited text on 2026-11-27.

Report an error in this question