Posts

Showing posts with the label Http Delete

Axios Delete Request With Body And Headers?

Answer : So after a number of tries, I found it working. Please follow the order sequence it's very important else it won't work axios.delete(URL, { headers: { Authorization: authorizationToken }, data: { source: source } }); axios.delete does support a request body. It accepts two parameters: url and optional config. You can use config.data to set the request body and headers as follows: axios.delete(url, { data: { foo: "bar" }, headers: { "Authorization": "***" } }); See here - https://github.com/axios/axios/issues/897 Here is a brief summary of the formats required to send various http verbs with axios: GET : Two ways First method axios.get('/user?ID=12345') .then(function (response) { // Do something }) Second method axios.get('/user', { params: { ID: 12345 } }) .then(function (response) { // Do something }) The two above are equivalent. Observe the params...

Body Of Http.DELETE Request In Angular2

Answer : 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); }); You are actually able to fool Angular2 HTTP into sending a body with a DELETE by using the request method. This is how: let body = { target: targetId, subset: "frui...