0

I developer an application in nodejs using methods for delete one data, what method is correct for delete data GET or POST?

i using EJS for render my template engine at framework express.

i am using

router.get('/delete-category/:id', (req, res) => {
    const id = req.params.id
    //delete
})

in this case i used method get, but what better method in this case, GET or POST.

router.post('/delete-category/:id', (req, res) => {
    const id = req.body.id
    if (id != undefined && id != null) {
      //delete  
}

Of course! the .ejs in this case i used one form and Method="POST"

1 Answer 1

1

If you're specifying a "delete" operation in a browser form, it should be a POST. From within a browser, think of GET as retrieving data and POST as modifying or deleting data.

If you're specifying a delete option in an API, you should use the actual DELETE verb in HTTP, but you can't use that in a browser form, so you can use a POST from a form.

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

Comments

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.