DEV Community

Discussion on: FullStack setup (Node.js, React.js and MongoDB)

Collapse
 
hofcsabagit profile image
hofcsabaGit

Hi there,

so I found app.delete(/api/product/:id, async (req, res) => {
const {id} = req.params;
let product = await Product.findByIdAndDelete(id);
return res.status(202).send({
error: false,
product
})
})

that I try to call from postman with:
localhost:5000/api/product/:id

With a raw body of JSON of:
{"name": "myName"}

but it sais:
Cannot DELETE /api/product/

Do you guys know what Im missing?

Thanks in advance!
Csaba

Collapse
 
pacheco profile image
Thiago Pacheco

Hi Csaba,

By the error, it could be something wrong with the definition of this app.delete method.
Does your backend log any error in the terminal when you test this endpoint?

If everything is correct in your code, the error could be the ID you are passing in the URL.
As this is just a simple tutorial and I wanted it to be short, it does not have validations but, in a final application, it should contain a lot of validations on the data we are trying to execute actions.

My suggestion to you is to check if the ID you are passing to the URL http://localhost:5000/api/product/<YOUR-PRODUCT-ID> is a valid ID.

Let me know if this helped you solve the problem and do not hesitate to ask if you have more questions.