1

I am trying to delete a certain input from my database. I cant seem to get the data to come through on an app.delete to know which entry to delete. However app.post gets the data. Here is my code

Client:

let userToDelete = {
    data:entryToDelete
}

httpRequest.delete(url, userToDelete)
    .then(function (response) {
        //...

Server

app.delete('/api/deleteEntry', function(req, res){
    console.log('going to delete', req.body);
    //...
});

now if I change to httpRequest.post and app.post, req.body console logs the data I send. Does a .delete request not get the data?

1 Answer 1

4

RFC2616 says:

The DELETE method requests that the origin server delete the resource identified by the Request-URI.

Request bodies are not explicitly disallowed for HTTP DELETE requests, but I wouldn't rely on them always being available. You'll have to include some sort of ID or primary key in your request URI, so that your server can pass that along to your database for deletion.

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

1 Comment

Thanks! I am decently new to node. Where I work we are a Java shop and I do primarily front end. Though we are implementing node now. I didnt realize this is how the java servers also do it. They pull a key from the request uri. We dont send data to a .delete. Thanks!

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.