Recall & Review
beginner
What is the purpose of setting headers in an Angular HTTP request?
Headers carry extra information with the request, like content type or authorization tokens, helping the server understand how to process the request.
Click to reveal answer
beginner
How do you add query parameters to an Angular HTTP GET request?
You use the HttpParams class to build key-value pairs and pass it in the options object under the 'params' property.Click to reveal answer
intermediate
Show a simple example of setting a custom header 'Authorization' in an Angular HTTP GET request.
const headers = new HttpHeaders().set('Authorization', 'Bearer token123');
this.http.get(url, { headers }).subscribe();Click to reveal answer
intermediate
What happens if you try to set headers or params directly as plain objects in Angular HTTP requests?
Angular accepts plain objects for headers and params, automatically converting them to HttpHeaders and HttpParams internally. However, using the dedicated classes is recommended for immutability, chainability, and advanced features.
Click to reveal answer
advanced
Why is immutability important when working with HttpHeaders and HttpParams in Angular?
HttpHeaders and HttpParams are immutable, so methods like set() return new instances. You must assign the result to keep changes.
Click to reveal answer
Which Angular class is used to add query parameters to an HTTP request?
✗ Incorrect
HttpParams is designed to hold query parameters for HTTP requests.
How do you add a header named 'Content-Type' with value 'application/json' in Angular?
✗ Incorrect
HttpHeaders is immutable and set() returns a new instance with the header added.
What must you do after calling set() on HttpParams to keep the changes?
✗ Incorrect
HttpParams is immutable; set() returns a new instance that must be saved.
Which option correctly passes headers and params in an Angular HTTP GET request?
✗ Incorrect
Headers and params must be passed inside an options object with keys 'headers' and 'params'.
Why should you use HttpHeaders and HttpParams instead of plain objects?
✗ Incorrect
While plain objects are accepted and converted, using HttpHeaders and HttpParams instances provides immutability, chainability, and proper handling for complex cases.
Explain how to set custom headers and query parameters in an Angular HTTP GET request.
Think about how Angular expects headers and params as special objects.
You got /4 concepts.
Describe why immutability matters when working with HttpHeaders and HttpParams in Angular.
Consider what happens if you forget to assign the result of set().
You got /4 concepts.