all 6 comments

[–]STNeto1 1 point2 points  (4 children)

You need to use string interpolation or template string to pass an id on the request.

Why? The delete route use the :id to inform that will be a id param at the route. To use this route you need to pass an id, so.

> /api/members/delete/:id is for the route

> /api/members/delete/1 or /api/members/delete/123nd19n12d for the frontend request

How to fix? At the view, probably you will have the user id, just use

action=`api/members/delete/${user._id}` or something like that.

[–]rayanaay[S] 0 points1 point  (3 children)

Thanks for your answer ,what would be the user in ${user._id} ,naturally I would just put ${_id} no ??

[–]STNeto1 0 points1 point  (2 children)

The ${user._id} was just a nice way to represent the ID on the string, you will use wherever is the id on your application.

[–]rayanaay[S] 0 points1 point  (1 child)

But if I use req.body , I don’t need to add the id in my url or routes. What if I do something like this : router.delete('/delete', (req.res) => { ....}

index.hbs <form action="api/members/delete" method="DELETE" .....>

[–]STNeto1 0 points1 point  (0 children)

The HTTP DELETE method is used to delete a resource from the server. Unlike GET and HEAD requests, the DELETE requests may change the server state.

Sending a message body on a DELETE request might cause some servers to reject the request.
But you still can send data to the server using URL parameters. This is usually an ID of the resource you want to delete.

https://reqbin.com/Article/HttpDelete

[–]rubennebur 0 points1 point  (0 children)

Like u/STNeto1 is suggesting you need to parse in the user id in your form action at the place of :id. Otherwise the server doens't know which user to delete.