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 removée unique id(that can be appended to the url), namely an authentication token, some collection info and some ancilliary data.
The most straightforward way I've found to do so is putting the authentication token in the request Headers, and other data in the body.
However, the Http module of Angular 2 doesn't quite approve of a DELETE request with a body, and trying to make this request
let headers= new Headers();
headers.append('access-token', token);
let body= JSON.stringify({
target: targetId,
subset: "fruits",
reason: "rotten"
});
let options= new RequestOptions({headers:headers});
this.http.delete('http://testAPI:3000/stuff', body,options).subscribe((ok)=>{console.log(ok)}); <------line 67
gives this error
app/services/test.service.ts(67,4): error TS2346: Supplied parameters do not match any signature of call target.
Now, am I doing something wrong syntax-wise? I'm pretty sure a DELETE body is supported per RFC
Are there better ways to send that data?
Or should I just dump it in headers and call it a day?
Any insight on this conundrum would be appreciated
If you use Angular 6 we can put body in
http.request
method.Reference from github
You can try this, for me it works.
Definition in http.js from the @angular/http:
The request doesn't accept a body so it seem your only option is to but your data in the URI.
I found another topic with references to correspond RFC, among other things: How to pass data in the ajax DELETE request other than headers
Below is the relevant code example for Angular 2/4/5 projects: