Angular

HttpClient & API Calls

HttpClient, observables, HTTP methods, interceptors, error handling, retry logic, headers, params, typed responses

22 interview questionsยท
Mid-Level
1

Which Angular module to import to use HttpClient in an application?

Answer

HttpClientModule (or provideHttpClient() with standalone) must be imported to enable HttpClient. This module automatically configures the necessary providers to inject HttpClient in services. It only needs to be imported once, typically in AppModule or the standalone app configuration.

2

What type does HttpClient.get() return by default?

Answer

All HttpClient methods return an Observable (cold observable) that emits the response once received. The Observable only starts the request upon subscription. This allows easy composition with RxJS operators and request cancellation via unsubscribe.

3

How to type the response of a GET request in Angular?

Answer

Using the generic type parameter allows the TypeScript compiler to verify the response type. For example, http.get<User[]>(url) ensures the response is an array of users. This prevents runtime errors and enables IDE autocompletion to access response properties.

4

Which HttpClient method to use to send data to create on the server?

5

What is the difference between PUT and PATCH in HTTP?

+19 interview questions

Master Angular for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free