Question presented to candidate: "Say we register three functional interceptors with provideHttpClient(). Walk me through exactly what happens when a component calls http.get(): which code runs in which order on the way out and on the way back, and what changes if a lazy route registers its own provideHttpClient()."
What a strong answer should cover:
provideHttpClient()wiresHttpClientto an internalHttpInterceptorHandler, which folds the registered functions into one chain withreduceRight, ending at theHttpBackend.- Request phase runs in array order; response phase runs in reverse, because each interceptor wraps everything after it (an onion).
- Code before
next()is the request phase; operators piped ontonext()are the response phase. - Short-circuiting: not calling
next()skips everything downstream (caches, mocks); per-request flags travel inHttpContext. - A built-in XSRF interceptor is always first; the chain is built lazily on the first request and each interceptor runs in an injection context.
- A child
provideHttpClient()creates an independent chain;withRequestsMadeViaParent()makes it forward to the parent.
Clarifying questions expected:
- "Do you want the order of side effects, or also how errors propagate back up?"
- "Are there route-level HttpClient providers in this app?"
Code / implementation expected: Yes β instrumented interceptors that log in/out order, plus a short-circuiting cache keyed by an HttpContextToken.