2
Hello, I’m trying to send a value of a form (id) that will be handled by express (I don’t know the technical terms for this, if you can help me too), I’ve looked a lot but I can’t pass the id parameter in the action and I can’t access the app.delete() function. How do I pass this to my app.delete?
My form:
<form action=<"/produtos"> method="DELETE">
<input id="id" type="text" name="id"/>
<input type="submit" value="REMOVER"/>
</form>
My app.delete (was taking Alura’s course):
app.delete('/produtos:id', function(req, res){
console.log(req.params.id);
var connection = app.infra.connectionFactory();
var ProdutosDAO = new app.infra.ProdutosDAO(connection);
var produtoID = req.params.id;
console.log(produtoID);
ProdutosDAO.remove(produtoID, function(erros, resultados){
if(erros) res.send(erros.message);
res.send("Produto " + produtoID + " removido");
});
});
It hasn’t worked yet. A friend said that Forms doesn’t support methods PUT And DELETE of HTTP. I thought I’d take a route like
/produtos/deletar/:id
, but don’t know how to pass this id on the route.– Icaro Rego Fernandes
@Icaroregofernandes you’re right, we only allow
PUT
andGET
. If you doGET
you can usereq.query.nomeDoParametro
, if you usePOST
you can usereq.body.nomeDoParametro
if you want to use by url/produtos/deletar/:id
you can usereq.params.id
.– Sergio