Body of Http.DELETE request in Angular2
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 works for Angular 2.x, 4.x and 5.x.
For versions 6.x onwards, Angular offers 15 different overloads. Check all overloads here: https://angular.io/api/common/http/HttpClient#delete
Usage sample:
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);
});
If you use Angular 6 we can put body in http.request
method.
Reference from github
You can try this, for me it works.
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
constructor(
private http: HttpClient
) {
http.request('delete', url, {body: body}).subscribe();
}
}