HttpClient and data loading: Angular 22 practice questions

HttpClient and data loading is 8% of the free Angular 22 mock (4 of 50 questions). Pick an answer to see right away whether it is correct, with the explanation and the documentation section it comes from.

NG.VII · Angular 22 practice question

What does adding withXhr() inside provideHttpClient(withXhr()) do in an Angular 22 application?

export const appConfig: ApplicationConfig = {
  providers: [provideHttpClient(withXhr())],
};
Choose one answer
Check answer and explanation

Correct answer: It switches HttpClient from the default fetch backend to XMLHttpRequest.

Explanation

HttpClient uses the fetch API by default, and passing withXhr() switches it to use XMLHttpRequest instead.

Common trap

Older Angular versions defaulted to XMLHttpRequest and used withFetch(), which is the opposite of Angular 22's default. withXhr() replaces the fetch backend with XMLHttpRequest rather than running both in a fallback chain.

Source: Angular docs: Setting up `HttpClient` — `withXhr`
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

A developer calls this.http.get('/api/items') inside a service method without subscribing to the returned value. What happens at runtime?

const items$ = this.http.get('/api/items');
Choose one answer
Check answer and explanation

Correct answer: No HTTP request is sent until something subscribes to items$.

Explanation

HttpClient returns cold Observables that act as blueprints, so no HTTP request is sent until something subscribes to items$.

Common trap

Sending immediately and caching describes a hot or Promise-based API like fetch, not a cold RxJS Observable. Leaving an Observable unsubscribed is completely valid in RxJS and never throws an error.

Source: Angular docs: Making HTTP requests — HTTP `Observable`s
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

A component has a required signal input userId and wants to automatically re-fetch user data whenever userId changes. Which definition uses httpResource correctly?

Choose one answer
Check answer and explanation

Correct answer: user = httpResource(() => `/api/user/${this.userId()}`);

Explanation

Passing a reactive function that returns the URL string, such as user = httpResource(() => `/api/user/${this.userId()}`), allows httpResource to track the signal and re-fetch on updates.

Common trap

Evaluating the template string eagerly passes a static string instead of a reactive function, so changes to userId would not trigger new requests. httpResource does not accept a signal as its first argument and a base URL string as its second argument.

Source: Angular docs: Reactive data fetching with `httpResource` — `Using httpResource`
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

A file-upload feature needs to display a live upload progress bar, but no upload progress events are arriving with the default HttpClient setup. Why?

Choose one answer
Check answer and explanation

Correct answer: The default fetch backend does not produce upload progress events.

Explanation

The default fetch backend has limitations, including not producing upload progress events, so switching to XMLHttpRequest via withXhr() is needed for upload progress.

Common trap

HttpClient does support upload progress events when configured with a backend that emits them, such as XMLHttpRequest. Switching to httpResource does not bypass the fetch API's lack of upload progress events.

Source: Angular docs: Setting up `HttpClient` — `withXhr`
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

An HttpClient request fails because the backend returns a 500 error. How does HttpClient surface this failure to subscribers?

Choose one answer
Check answer and explanation

Correct answer: It emits an HttpErrorResponse through the Observable error channel.

Explanation

HttpClient wraps network, timeout, and backend failures in an HttpErrorResponse and delivers it through the Observable error channel.

Common trap

HttpClient does not swallow HTTP errors into null values; subscribers must handle failures via the error callback or catchError. HttpClient methods return Observables rather than Promises, and they wrap failures in HttpErrorResponse.

Source: Angular docs: Making HTTP requests — Handling request failure
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

An HttpClient request times out before the server responds. What value does the status property have on the resulting HttpErrorResponse?

Choose one answer
Check answer and explanation

Correct answer: 0

Explanation

Both network errors and client-side timeout errors produce an HttpErrorResponse with a status code of 0.

Common trap

408 is an HTTP status code returned by a server, whereas client-side timeouts never receive a server status and therefore report 0. -1 is a common sentinel value in some libraries, but Angular's HttpErrorResponse uses 0 for network and timeout failures.

Source: Angular docs: Making HTTP requests — Handling request failure
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

In an interceptor running with the fetch backend, how can you check whether an incoming HTTP response was the result of a redirect?

Choose one answer
Check answer and explanation

Correct answer: Inspect the response's redirected property.

Explanation

When HttpClient uses the fetch backend, responses include a redirected property aligned with the native Fetch API that indicates whether a redirect occurred.

Common trap

A redirected request often ends with a final 200 OK response, so checking status === 200 cannot tell you if a redirect happened. There is no isRedirected() method on HttpResponse; redirect status is exposed as the redirected property.

Source: Angular docs: Interceptors — Working with redirect information
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

When a developer supplies a parse function to httpResource that returns a validated User object, how is the TypeScript type of the resource's value determined?

Choose one answer
Check answer and explanation

Correct answer: It is inferred from the return type of the parse function.

Explanation

When using the parse option, the type of the resource's value is inferred from the return type of the parse function.

Common trap

Providing a typed parse function eliminates the need for manual casting in templates. You do not need a redundant generic type argument because httpResource derives the resource value type from parse.

Source: Angular docs: Reactive data fetching with `httpResource` — Response parsing and validation
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

Two components subscribe to the exact same Observable instance returned by a single HttpClient.get('/api/profile') call. How many network requests are dispatched?

Choose one answer
Check answer and explanation

Correct answer: Two separate requests, because each subscription triggers its own independent request.

Explanation

Because HttpClient produces cold Observables, subscribing multiple times triggers two separate requests, because each subscription triggers its own independent request.

Common trap

HttpClient does not apply shareReplay or multicasting by default; you must add an RxJS operator if you want sharing. Timing does not merge cold Observable subscriptions; even simultaneous subscriptions dispatch separate HTTP calls.

Source: Angular docs: Making HTTP requests — HTTP `Observable`s
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

A team uses httpResource in a new Angular 22 application without any custom interceptors or XSRF configuration. What is required in appConfig?

Choose one answer
Check answer and explanation

Correct answer: Nothing extra is needed because httpResource uses the globally available HttpClient.

Explanation

Nothing extra is needed because httpResource uses the globally available HttpClient; provideHttpClient(...) is only required when configuring features such as interceptors or XSRF options.

Common trap

There is no separate provideHttpResource() provider function; httpResource builds directly on HttpClient. Calling provideHttpClient() was required in older Angular setups, but httpResource now relies on the globally available HttpClient by default.

Source: Angular docs: Reactive data fetching with `httpResource` — `Using httpResource`
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

A developer wants an interceptor to attach an X-Trace-Id header to every outgoing request. Which snippet correctly creates the updated request?

const reqWithHeader = req.clone({
  headers: req.headers.set('X-Trace-Id', 'abc-123'),
});
Choose one answer
Check answer and explanation

Correct answer: The snippet is valid because req.clone() pairs with the immutable req.headers.set() update.

Explanation

The snippet is valid because req.clone() pairs with the immutable req.headers.set() update to produce a new HttpRequest with the added header.

Common trap

HttpHeaders is immutable, so req.headers.set() returns a new HttpHeaders instance rather than mutating in place and returning void. req.clone() accepts a configuration object that supports updating headers, params, and other request properties.

Source: Angular docs: Interceptors — Modifying requests
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

A developer wants to opt into upload and download progress events on an HttpClient request. Why are they off by default, and which options enable them?

Choose one answer
Check answer and explanation

Correct answer: They are disabled due to performance cost and enabled with reportUploadProgress and reportDownloadProgress.

Explanation

Progress events carry a performance cost, so they are disabled by default and enabled with reportUploadProgress and reportDownloadProgress.

Common trap

Progress events are not disabled for security reasons, and trackUpload/trackDownload are not valid HttpClient options. Progress events do not cause extra network round-trips, and enableProgressEvents is not the option name.

Source: Angular docs: Making HTTP requests — Receiving raw progress events
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

A team wants to validate API responses fetched by httpResource using Zod schemas. Which option on httpResource integrates the validation function?

Choose one answer
Check answer and explanation

Correct answer: parse

Explanation

You integrate schema validation libraries such as Zod or Valibot with httpResource by providing a parse option.

Common trap

validate is a plausible name, but httpResource expects the option to be named parse. schema is not an httpResource option; the library's parsing function is passed to parse instead.

Source: Angular docs: Reactive data fetching with `httpResource` — Response parsing and validation
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

While debugging a CORS issue in an interceptor with the fetch backend enabled, which property on the response reveals how the browser handled CORS policies and request mode?

Choose one answer
Check answer and explanation

Correct answer: responseType

Explanation

With the fetch backend, responses expose a responseType property aligned with the Fetch API that shows how the browser processed CORS policies and request mode.

Common trap

corsMode is not a property on Angular HTTP responses; request mode is configured on requests, while the response exposes responseType. fetchStatus is a fabricated property name; HTTP status codes are exposed via status and statusText.

Source: Angular docs: Interceptors — Working with response types
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


NG.VII · Angular 22 practice question

Why must an Angular HTTP interceptor avoid directly mutating properties on the incoming HttpRequest instance?

Choose one answer
Check answer and explanation

Correct answer: Because HttpRequest instances are immutable, so changes must be applied by cloning the request.

Explanation

Most aspects of HttpRequest and HttpResponse are immutable, so interceptors must use the .clone() method to create a modified copy.

Common trap

HttpRequest is not a reverting proxy; its properties are designed to be immutable rather than silently rolled back. Immutability applies to HttpRequest regardless of whether the fetch or XMLHttpRequest backend is active.

Source: Angular docs: Interceptors — Modifying requests
Checked against the cited text on 2026-11-25.

Report an error in this question

Open this question on its own page


Back to all topics