HttpClient & API Calls
HttpClient, observables, HTTP methods, interceptors, error handling, retry logic, headers, params, typed responses
1Which Angular module to import to use HttpClient in an application?
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.
2What type does HttpClient.get() return by default?
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.
3How to type the response of a GET request in Angular?
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.
Which HttpClient method to use to send data to create on the server?
What is the difference between PUT and PATCH in HTTP?
+19 interview questions
Other Angular interview topics
TypeScript Basics
TypeScript Advanced
Angular Fundamentals
Components & Lifecycle
Services & Dependency Injection
Angular Modules Organization
Angular CLI
Directives & Pipes
Routing & Navigation
Reactive Forms
Template-driven Forms
RxJS Fundamentals
RxJS Operators
Basic State Management
Change Detection
Angular Signals
Standalone Components
Angular Unit Testing
End-to-End Testing
Build & Optimization
NgRx Fundamentals
NgRx Advanced
Angular Architecture
Performance Optimization
Security & Best Practices
Advanced RxJS Patterns
Angular Universal & SSR
Angular Micro-frontends
Master Angular for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free