Bird
0
0

How do you correctly send an Angular HTTP GET request with custom headers and multiple query parameters?

hard🚀 Application Q9 of 15
Angular - HTTP Client
How do you correctly send an Angular HTTP GET request with custom headers and multiple query parameters?
const headers = new HttpHeaders().set('X-API-KEY', 'abc123');
const params = new HttpParams().set('status', 'active').set('limit', '5');
// What is the correct way to send the request?
Athis.http.get('/users', { headers, params }).subscribe();
Bthis.http.get('/users', { headers: headers, queryParams: params }).subscribe();
Cthis.http.get('/users', { headers: headers, search: params }).subscribe();
Dthis.http.get('/users', { header: headers, params: params }).subscribe();
Step-by-Step Solution
Solution:
  1. Step 1: Check Angular HttpClient options

    The options object accepts headers and params keys.
  2. Step 2: Verify correct keys

    Use headers for HttpHeaders and params for HttpParams.
  3. Final Answer:

    this.http.get('/users', { headers, params }).subscribe(); -> Option A
  4. Quick Check:

    Use exact option keys: headers and params [OK]
Quick Trick: Use { headers, params } keys in HttpClient options [OK]
Common Mistakes:
MISTAKES
  • Using incorrect option keys like queryParams or search
  • Passing headers or params incorrectly
  • Not chaining subscribe() after get()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes