I don't understand a couple of thing about how to use POST and PUT
first of all if you have a form with method="post"
can you use app.put("/path") to change data?
I know I could change specific data from req.body.name through using app.post() with mongoose. So why would I need PUT?
Second of all, I noticed that if you usemethod="PUT"
on the form and i click submit i get a query string of the data in the url. even if i use res.redirect("/path")
, I get the query string and the page doesn't redirect. Is that normal? why do I get the query string? and why doesn't it redirect
app.put("/myaction", function(req, res){
//originally i had it at req.body.name then browser said that it "cannot POST"
//so I changed the method to PUT so thats why used req.query.name because I got
//the query string. if
name = req.query.name;
Name.findOneAndUpdate({name : name}, {name : " Itwas changed through PUT "}, function(err, result){
console.log("result : ", result);
res.redirect("/result")
})
})
If im supposed to get these querystring how should i update the database?
Also I've noticed that if you have app.post("/path") and app.put("/path") express will use app.post especially when you have method="post" so should you use put if you want to use the same form if you want to allow the user to change their name if they enter it? in this case the new name would be 'Itwas changed through PUT'