What is the HttpClient in Angular?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Angular development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

Angular's HttpClient (from @angular/common/http) is the recommended way to make HTTP requests. It returns Observables (not Promises) and provides type safety, interceptors, and automatic JSON parsing. Setup: import HttpClientModule in AppModule (or use provideHttpClient() in standalone apps). Inject: constructor(private http: HttpClient) {}. Methods: this.http.get<User[]>("/api/users"), this.http.post<User>("/api/users", userData), this.http.put<User>("/api/users/1", userData), this.http.patch<User>("/api/users/1", partial), this.http.delete<void>("/api/users/1"). Type parameters: generic type specifies the response body type — enables TypeScript intellisense on the result. Options: this.http.get("/api/users", { params: new HttpParams().set("page", "2"), headers: new HttpHeaders({ "Authorization": "Bearer " + token }), observe: "response" }). observe option: "body" (default — just data), "response" (full HttpResponse with status, headers), "events" (stream of all HTTP events including upload progress). responseType: "json" (default), "text", "blob", "arraybuffer". Error handling: pipe with catchError from RxJS. The returned Observable does NOT make the HTTP request until subscribed — "cold" Observable. HttpClientModule vs HttpClient standalone: in Angular 15+, use provideHttpClient(withInterceptorsFromDi()) in main.ts.

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.