HTTP Questions with Answers

6 practice questions on HTTP (Angular) with answers and step-by-step solutions. Try 6 samples below, then practise all 6 free in the AptiNest app.

Sample questions

Question 1Easy

Which Angular service performs HTTP calls?

  1. XMLService
  2. FetchService
  3. AjaxClient
  4. HttpClient

Answer: D. HttpClient

Explanation

HttpClient returns observables.

Step-by-step solution

  1. Name the service.

Why the other options are wrong

  • A. XMLService is not an Angular class; HttpClient is the built-in one.
  • B. FetchService is not an Angular class; HttpClient does HTTP calls.
  • C. AjaxClient is not an Angular class; HttpClient is the built-in one.

Question 2Medium

Which RxJS operator is commonly used with HttpClient to handle errors?

  1. debounceTime
  2. distinctUntilChanged
  3. scan
  4. catchError

Answer: D. catchError

Explanation

catchError can recover or rethrow.

Step-by-step solution

  1. Error handling operator.

Why the other options are wrong

  • A. debounceTime delays values; it does not handle errors.
  • B. distinctUntilChanged filters repeats; it does not handle errors.
  • C. scan accumulates values; it does not catch errors.

Question 3Medium

Why does this call usually need subscribe()?

this.http.get('/api/items')
  1. The request is sent immediately and subscribe only logs
  2. HttpClient requests are cold observables that run only when subscribed
  3. subscribe converts JSON to objects
  4. subscribe is required by the router

Answer: B. HttpClient requests are cold observables that run only when subscribed

Explanation

Without subscribing (or async pipe) no request is sent.

Step-by-step solution

  1. Cold observable.

Why the other options are wrong

  • A. HttpClient requests do not run until subscribed, so nothing is sent.
  • C. JSON parsing is automatic.
  • D. The router does not need subscribe; HTTP requests need it to run.

Question 4Medium

What is an HTTP interceptor used for?

  1. Routing browser requests to the matching component and managing the browser history stack
  2. Compiling templates ahead of time
  3. Inspecting or modifying requests and responses globally, such as adding an auth header
  4. Caching only the image responses

Answer: C. Inspecting or modifying requests and responses globally, such as adding an auth header

Explanation

Interceptors form a chain around HttpClient.

Step-by-step solution

  1. Cross-cutting concerns.

Why the other options are wrong

  • A. Interceptors do not route requests or manage browser history.
  • B. Interceptors handle HTTP traffic, not template compilation.
  • D. Interceptors act on all HTTP requests, not only image responses.

Question 5Hard

An interceptor must call next.handle(req) (or next(req) in functional style) because:

  1. Otherwise the request never continues to the backend
  2. It logs the request automatically to the browser console
  3. It unsubscribes the request
  4. It clones the request for caching

Answer: A. Otherwise the request never continues to the backend

Explanation

The chain proceeds only when passed along.

Step-by-step solution

  1. Interceptors form a chain.

Why the other options are wrong

  • B. Calling next does not log requests to the console automatically.
  • C. Calling next does not unsubscribe the request.
  • D. Calling next does not clone the request for caching.

Question 6Hard

Why does HttpRequest need clone() to add a header in an interceptor?

  1. Clones are faster
  2. Headers are read-only on the server
  3. Requests are immutable, so you create a modified copy
  4. Angular forbids headers

Answer: C. Requests are immutable, so you create a modified copy

Explanation

req.clone({setHeaders: ...}).

Step-by-step solution

  1. Immutable request.

Why the other options are wrong

  • A. Cloning is needed for immutability, not because it is faster.
  • B. Headers are not read-only on the server; the request is immutable.
  • D. Angular does not forbid headers; requests are just immutable.

Practise all 6 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Angular topics · All topics