2

I want to delete the tag created using http post. here is the code that i have tried.

$http({
    method: 'DELETE',
    url: '/api/tags',
    data: [vm.tags.name]
}).success(function(data) {
    console.log('Gets DELETED');
    vm.tags.name = data;
}).error(function(data) {
    console.log('Does not get DELETED');
});

However this didn't work and it only sends an array with [null]. So is there something i don't see or understand here. I mean, if the POST works it should work the same way with DELETE, right? By the way it shows the log "Gets DELETED" but didn't do so.

2 Answers 2

5

I got the solution! In my case HTTP 1.1 was able to send the body, but the header was not able so use the content of JSON. So, by adding headers: {'Content-Type': 'application/json;charset=utf-8'} to the data: field of the $http.delete it worked and the array got send.

I hope this helps someone.

Thanks for the answers!

Sign up to request clarification or add additional context in comments.

Comments

3

Take a look in this answer, if you send something in the body of DELETE is ignored.

You should send in the path like this:

current/path?id=1&id=2&id=3&id=4

It's like the GET method, you are not allowed to send anything in the body.

UPDATE

If you make a request with the URL parameters in the example, you will receive a object like this:

{ id : [1, 2, 3, 4] }

4 Comments

but the article states that HTTP 1.1 allows this?
ok, but lets assume that is the problem, how can i send the array in the path i tried: 'api/tags/' + [ myarray ]
I don't think so, if you take a look in the HTTP document for delete you will see that only parameters mentioned is in the URI.
If you want to receive a array of IDs for example, you can send multiple strings in the URL like in the example, I updated with a example of the final object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.