Angular Architecture & Modules Quiz – 20 Questions with Answers
20 questions · 15 min · Medium
Test your knowledge of Angular HttpClient and HTTP interceptors, including HTTP requests, HttpClientModule, provideHttpClient, request methods, headers, responses, error handling, and interceptors.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. HttpClient
Angular's HttpClient service provides methods for making HTTP requests and communicating with backend APIs.
A. @angular/common/http
HttpClient and related HTTP APIs are provided by the @angular/common/http package.
A. provideHttpClient()
provideHttpClient() is the modern provider-based way to configure HttpClient in Angular applications.
A. get()
The HttpClient get() method is commonly used to send HTTP GET requests and retrieve data from an API.
B. post()
The post() method is commonly used to send data to a server, such as when creating a new resource.
A. An Observable
Angular HttpClient methods generally return RxJS Observables, which emit the HTTP response when the request completes.
A. To intercept and modify HTTP requests or responses
Interceptors can inspect, modify, or react to outgoing HTTP requests and incoming HTTP responses.
A. Adding an authentication token to outgoing requests
Interceptors are commonly used to add authorization headers or tokens to requests sent to protected APIs.
A. HttpRequest
HttpRequest represents an outgoing HTTP request and contains information such as the URL, method, headers, body, and parameters.
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.
B. clone()
The clone() method creates a modified copy of an HttpRequest, for example by adding or changing headers.
A. HttpInterceptor
Class-based interceptors implement the HttpInterceptor interface and provide an intercept() method.
A. next.handle(req)
In a class-based interceptor, the HttpHandler's handle() method passes the request along the interceptor chain.
A. RxJS operators such as catchError()
Interceptors can use RxJS operators such as catchError() to inspect, transform, log, or handle HTTP errors.
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.