How does Angular s HttpInterceptor modify outgoing requests

0 votes
Can you tell me How does Angular's HttpInterceptor modify outgoing requests?
Feb 24 in Angular by Nidhi
• 10,860 points
47 views

1 answer to this question.

0 votes

An HttpInterceptor in Angular is used to modify outgoing HTTP requests before they are sent to the server. It is commonly used for adding authentication tokens, logging, or modifying headers.

Implementation Example: Adding an Authorization Header

import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http';

import { Injectable } from '@angular/core';

@Injectable()

export class AuthInterceptor implements HttpInterceptor {

  intercept(req: HttpRequest<any>, next: HttpHandler) {

    const modifiedReq = req.clone({

      setHeaders: { Authorization: `Bearer your-token-here` }

    });

    return next.handle(modifiedReq);

  }

}

answered Feb 24 by Navya

Related Questions In Angular

0 votes
1 answer
0 votes
1 answer

How does the @Component directive define Angular components?

The @Component decorator defines a component by ...READ MORE

answered Feb 26 in Angular by Navya
30 views
0 votes
1 answer

How compile, controller, pre-linking and post linking works in Angularjs?

Explanation of compile and link process don't ...READ MORE

answered Jan 31, 2020 in Angular by Niroj
• 82,840 points
1,707 views
0 votes
1 answer

How can we achieve transclusion in AngularJs?

Hii,  In order to know what transclusion is ...READ MORE

answered Feb 5, 2020 in Angular by Niroj
• 82,840 points
762 views
0 votes
1 answer

Should I use map or switchmap when using angular http module?

When working with the Angular HTTP module, ...READ MORE

answered Feb 24 in Angular by Navya
45 views
0 votes
1 answer

How does BehaviorSubject differ from Subject in state management?

Feature Subject BehaviorSubject Initial Value No initial value Requires an initial value Last ...READ MORE

answered Feb 24 in Node-js by Navya
39 views
0 votes
1 answer
0 votes
1 answer

What is the use of takeUntil to cancel a subscription?

takeUntil is an RxJS operator used to ...READ MORE

answered Feb 24 in Node-js by Navya
49 views
0 votes
1 answer

How does Angular work?

Angular is a TypeScript-based front-end framework for ...READ MORE

answered Feb 25 in Angular by Navya
39 views
0 votes
0 answers

How does takeUntil() help in cleaning up Observables?

i want know with the help of ...READ MORE

4 days ago in Angular by Nidhi
• 10,860 points
26 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP