0
app.delete('/poems/delete:ids',(req,res,next)=>{
    //here req.params.ids carries the multiple id i.e 1,2,3

});

In the above code, how can I delete all data with the requested ids that is the data's containing ids 1,2,3

 this.http.delete('http://localhost:3000/poems/delete' + ['1','3','4']);
  • 2 things - why use the `DELETE` verb with a CRUD URL? Also, if `ids` are arbitrary then you'd be best using `POST` and passing the IDs up in the body given URLs have a [maximum length](https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers). – James Mar 08 '19 at 14:52
  • ok, thank u so much. – Bhupendra Thapa Mar 08 '19 at 15:01
  • can u please, why req.params.ids stores the values in the format like: 1,2,3 instead of [1,2,3] . – Bhupendra Thapa Mar 08 '19 at 15:05

1 Answers1

1

The best practice in this case is to submit a POST request, whose body is an array of IDs. In that case, your controller would get req.body.ids and delete them accordingly.

The DELETE HTTP Method is used for single deletions.

TheLebDev
  • 531
  • 6
  • 18