Bird
0
0

You want to add a custom header 'X-App-Version' with value '1.0' to all outgoing HTTP requests in your Angular app. Which is the best way to do this?

hard🚀 Application Q15 of 15
Angular - HTTP Client
You want to add a custom header 'X-App-Version' with value '1.0' to all outgoing HTTP requests in your Angular app. Which is the best way to do this?
AAdd the header manually in every HTTP call
BModify the HttpClient service to include the header
CCreate an interceptor that clones requests and sets the header, then register it globally
DUse a component to add the header before each request
Step-by-Step Solution
Solution:
  1. Step 1: Understand global header addition

    Manually adding headers everywhere is error-prone and repetitive.
  2. Step 2: Use interceptor for centralized modification

    Interceptors allow modifying all requests in one place by cloning and setting headers, then registering globally.
  3. Final Answer:

    Create an interceptor that clones requests and sets the header, then register it globally -> Option C
  4. Quick Check:

    Global header addition = interceptor + clone + register [OK]
Quick Trick: Use interceptor to add headers globally [OK]
Common Mistakes:
MISTAKES
  • Adding headers manually in every call
  • Trying to modify HttpClient directly
  • Using components for HTTP header changes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes