I\'m trying to talk to a somewhat RESTful API from an Angular 2 frontend.
To remove some item from a collection, I need to send some other data in addition to the re
The http.delete(url, options) does accept a body. You just need to put it within the options object.
http.delete('/api/something', new RequestOptions({
headers: headers,
body: anyObject
}))
Reference options interface: https://angular.io/api/http/RequestOptions
UPDATE:
The above snippet only work for Angular 2.x, 4.x and 5.x.
For versions 6.x and 7.x, Angular offers different overloads for what you need. Check all overloads here: https://angular.io/api/common/http/HttpClient#delete
const options = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
}),
body: {
id: 1,
name: 'test',
},
};
this.httpClient
.delete('http://localhost:8080/something', options)
.subscribe((s) => {
console.log(s);
});