I\'m trying to do an api call from my angular app. What I want to do is send a post request to the api with a command param. I have done a lot of server side testing as well as
Let said our backend looks like this:
public async Task Post([FromBody] IList roles, string notes) {
}
We have a HttpService like this:
post(url: string, body: any, headers?: HttpHeaders, params?: HttpParams): Observable {
return this.http.post(url, body, { headers: headers, params});
}
Following is how we can pass the body and the notes as parameter: // how to call it
const headers: HttpHeaders = new HttpHeaders({
'Authorization': `Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXX`
});
const bodyData = this.getBodyData(); // get whatever we want to send as body
let params: HttpParams = new HttpParams();
params = params.set('notes', 'Some notes to send');
this.httpService.post(url, bodyData, headers, params);
It worked for me (using angular 7^), I hope is useful for somebody.