My Angular Service is currently making http requests, but I am looking to retrieve headers for these requests from a Promise. The current setup involves converting the promise to an Observable:
export class SomeService {
constructor(private http: HttpClient, private auth: AuthenticationService) {}
getInfo(id: string): Observable<any> {
return this.auth.getToken().pipe(mergeMap((token: any) => {
let httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token
})
}
return this.http.get(`${this.serverURL}/info`, httpOptions);
}))
}
}
getToken() {
return from(this.storage.get(TOKEN_KEY));
}
However, making multiple requests for 20-50 requests is not ideal. I aim to fetch the auth token once and use it for all requests. Additionally, there is another header coming from a Promise that needs to be used in the requests. Therefore, I am exploring ways to retrieve async headers only once, preferably in the constructor. How can I accomplish this in this scenario?