Reputation: 2057
I'm trying to consume an API which has to be specific for given users based on a variable: their cooker ID.
As such, below is the script I wrote in order to achieve that: I'm parsing the variable as ${cookieuid}
in a string so as to form the URL;
getBellNotification() {
let cookieuid = this.currentUser;
let headers = new Headers();
this.authorizeHeaders(headers);
return this.http.get(
this.config.apiUrl + 'api/supplier-notification/${cookieuid}?_format=json', {
headers: headers
}
)
.map(response => response.json())
.catch(this.handleErrorObservable);
}
It is not working as expected as I get the result below, with undesired special characters:
http://<url>/api/supplier-notification/$%7Bcookieuid%7D?_format=json
What am I doing wrong and how can I achieve that?
I've tried other ways but still cannot get it working.
Upvotes: 0
Views: 3883
Reputation: 222712
Try this
getBellNotification(){
let cookieuid = this.currentUser;
const url = `${this.config.apiUrl}/api/supplier-notification/${cookieuid}?_format=json`;
let headers = new Headers();
this.authorizeHeaders(headers);
return this.http.get(url, { headers: headers })
.map(response => response.json())
.catch(this.handleErrorObservable);
}
Upvotes: 2