Besides sending (or requesting) the actual data to the server API, there's also often the need to send further metadata th At helps the server to correctly interpret our request. Such data is the most often sent using HTTP headers. In this lesson we learn what to leverage Angular ' s to HttpClient set such headers. Note that if you had to continuously send certain application headers to the backend, a for each single HTTP call Being made, your may is better served by placing them in an HTTP interceptor.
Import {injectable} from ' @angular/core 'rxjs/observable 'httpheaders' @angular/common/http '; @Injectable () Export class Peopleservice { constructor (private http:httpclient) {} fetchpeople (): Observable <Object> { returnthis. http . Get (' Data/people.json ') , { newhttpheaders(). Set (' App-language ', ' en ') }); }}
[Angular] Set Metadata in HTTP Headers with Angular httpheaders