0
I have a sequence of methods (get, post, put, delete), however the put method is wrong and I do not know how to solve.
this is the code snippet:
router.route('/')
.get((req, res) => res.status(200).send('Lista de Produtos'))
.post((req, res) => res.status(201).send(req.body))
.put(':id',(req, res, next) => {
const id = req.params.id;
res.status(201).send({
id: id,
item: req.body
});
})
.delete((req, res) => res.send('Remove Produtos'))
And this is the mistake:
Error: Route.put() requires a callback Function but got a [Object String]
I need the url to forward an id as for example : http://localhost:3000/products/123
The id would be 123..
and the answer would be { "id" means "123", "item": { } }
I understood Rodrigo Melo, this was the solution I had also come up with, but I found it a little weak because I only need to use the id in one method, so I need to add every extra line of code.. But that’s okay, it’s running and working!! I liked some utilities of the owner of the post you indicated! I will deal with it calmly. Thanks!!
– Vitor Pereira