Q1. How do you make a GET request with HttpClient?
Use the get method. Example:
this.http.get(''/api/users'').subscribe(users => this.users = users);
The get method is generic to specify the expected response type. It returns an Observable that you subscribe to.Q2. How do you make a POST request?
Use the post method with the body. Example:
const newUser = { name: ''John'' };
this.http.post(''/api/users'', newUser).subscribe(user => console.log(user));
The second argument is the request body, which will be JSON-serialized.Q3. How do you make PUT and DELETE requests?
PUT:
this.http.put(''/api/users/1'', updatedUser).subscribe();
DELETE: this.http.delete(''/api/users/1'').subscribe();
Q4. How do you add headers to requests?
Use HttpHeaders and pass in options. Example:
const headers = new HttpHeaders().set(''Authorization'', ''Bearer token'');
this.http.get(''/api/users'', { headers }).subscribe();
Q5. How do you pass URL parameters?
Use HttpParams. Example:
const params = new HttpParams().set(''page'', ''1'').set(''sort'', ''name'');
this.http.get(''/api/users'', { params }).subscribe();
