Skip to content
QuiznExam

HTTP Client & Interceptors in Angular

Test your knowledge of Angular HttpClient and HTTP interceptors, including HTTP requests, HttpClientModule, provideHttpClient, request methods, headers, responses, error handling, and interceptors.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. Which Angular service is commonly used to make HTTP requests to a backend API?

    • A. HttpClient
    • B. HttpService
    • C. ApiClient
    • D. HttpRequestService
    Show answer

    A. HttpClient

    Angular's HttpClient service provides methods for making HTTP requests and communicating with backend APIs.

  2. 2. Which package provides Angular's HttpClient?

    • A. @angular/common/http
    • B. @angular/http-client
    • C. @angular/core/http
    • D. @angular/network
    Show answer

    A. @angular/common/http

    HttpClient and related HTTP APIs are provided by the @angular/common/http package.

  3. 3. In a modern standalone Angular application, which function is commonly used to enable HttpClient?

    • A. provideHttpClient()
    • B. enableHttp()
    • C. useHttpClient()
    • D. configureHttp()
    Show answer

    A. provideHttpClient()

    provideHttpClient() is the modern provider-based way to configure HttpClient in Angular applications.

  4. 4. Which HttpClient method is commonly used to retrieve data from an API?

    • A. get()
    • B. fetch()
    • C. retrieve()
    • D. read()
    Show answer

    A. get()

    The HttpClient get() method is commonly used to send HTTP GET requests and retrieve data from an API.

  5. 5. Which HttpClient method is commonly used to send data to a server to create a resource?

    • A. get()
    • B. post()
    • C. read()
    • D. fetch()
    Show answer

    B. post()

    The post() method is commonly used to send data to a server, such as when creating a new resource.

  6. 6. What does Angular HttpClient return by default for most HTTP methods?

    • A. An Observable
    • B. A Promise only
    • C. A string only
    • D. A DOM element
    Show answer

    A. An Observable

    Angular HttpClient methods generally return RxJS Observables, which emit the HTTP response when the request completes.

  7. 7. What is the primary purpose of an HTTP interceptor in Angular?

    • A. To intercept and modify HTTP requests or responses
    • B. To create HTML templates
    • C. To replace Angular components
    • D. To compile TypeScript
    Show answer

    A. To intercept and modify HTTP requests or responses

    Interceptors can inspect, modify, or react to outgoing HTTP requests and incoming HTTP responses.

  8. 8. Which task is a common use case for an HTTP interceptor?

    • A. Adding an authentication token to outgoing requests
    • B. Creating CSS animations
    • C. Defining Angular routes
    • D. Generating TypeScript classes
    Show answer

    A. Adding an authentication token to outgoing requests

    Interceptors are commonly used to add authorization headers or tokens to requests sent to protected APIs.

  9. 9. Which object represents an outgoing HTTP request in Angular?

    • A. HttpRequest
    • B. HttpResponseRequest
    • C. RequestObject
    • D. AngularRequest
    Show answer

    A. HttpRequest

    HttpRequest represents an outgoing HTTP request and contains information such as the URL, method, headers, body, and parameters.

  10. 10. Are Angular HttpRequest objects generally mutable?

    • A. Yes, all properties can be changed directly
    • B. No, they are immutable and should be modified using clone()
    • C. Only their URL can be changed directly
    • D. Only their body can be changed directly
    Show answer

    B. No, they are immutable and should be modified using clone()

    HttpRequest instances are immutable. Interceptors typically create a modified copy using the clone() method.

  11. 11. Which method is commonly used by an interceptor to create a modified copy of an HttpRequest?

    • A. copy()
    • B. clone()
    • C. modify()
    • D. duplicate()
    Show answer

    B. clone()

    The clone() method creates a modified copy of an HttpRequest, for example by adding or changing headers.

  12. 12. Which interface is used for class-based HTTP interceptors in Angular?

    • A. HttpInterceptor
    • B. HttpHandler
    • C. HttpInterceptorService
    • D. HttpMiddleware
    Show answer

    A. HttpInterceptor

    Class-based interceptors implement the HttpInterceptor interface and provide an intercept() method.

  13. 13. What does an interceptor typically call to pass a request to the next interceptor or the backend?

    • A. next.handle(req)
    • B. next.send(req)
    • C. next.forward(req)
    • D. backend.process(req)
    Show answer

    A. next.handle(req)

    In a class-based interceptor, the HttpHandler's handle() method passes the request along the interceptor chain.

  14. 14. Which interceptor feature can be used to handle errors from HTTP requests?

    • A. RxJS operators such as catchError()
    • B. CSS selectors
    • C. Angular templates only
    • D. HTML attributes
    Show answer

    A. RxJS operators such as catchError()

    Interceptors can use RxJS operators such as catchError() to inspect, transform, log, or handle HTTP errors.

  15. 15. Which statement best describes the benefit of using HTTP interceptors?

    • A. They centralize common HTTP concerns such as authentication, logging, and error handling
    • B. They eliminate the need for APIs
    • C. They make every HTTP request synchronous
    • D. They replace all Angular services
    Show answer

    A. They centralize common HTTP concerns such as authentication, logging, and error handling

    Interceptors provide a centralized place for cross-cutting HTTP concerns, reducing the need to repeat the same logic in individual services.