javascript - Using the PUT method with Express.js -


i'm trying implement update functionality express.js app, , i'd use put request send new data, keep getting errors using put. i've read, it's matter of using app.put, isn't working. i've got following in routes file:

send = function(req, res) {      req.send(res.locals.content); };  app.put('/api/:company', function(res,req) {     res.send('this update'); }, send); 

when use postman make put request, "cannot put /api/petshop" error. don't understand why can't put, or what's going wrong.

you may lacking actual update function. have put path returning result client missing part when tell database update data.

if you're using mongodb , express, write like:

app.put('/api/:company', function (req, res) {     var company = req.company;      company = _.extend(company, req.body);      company.save(function(err) {     if (err) {         return res.send('/company', {             errors: err.errors,             company: company         });     } else {         res.jsonp(company);     }  });  

this mean stack project may covers crud functionality used here swapping articles companies. same same.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -