njsetn:express_post_bodies_and_params
(...) var bodyParser = require ("body-parser"); var skierTerms = ... app.use(bodyParser.urlencoded({ extended: false })); app.use(function(req,res, next) { console.log(`${req.method} request for '${req.url}' - ${JSON.stringify(req.body)}`); next(); }); app.use(cors()); app.get("/dictionary-api", function(req, res) { res.json(skierTerms); }); app.post("/dictionary-api", function(req, res) { skierTerms.push(req.body); res.json(skierTerms); }); app.delete("/dictionary-api/:term", function(req, res) { skierTerms = skierTerms.filter(function(definition) { // predicate, retourne soit true soit false return definition.term.toLowerCase() !== req.params.term.toLowerCase(); }); req.json(skierTerms); }); (...)
njsetn/express_post_bodies_and_params.txt · Last modified: 2016/03/27 20:21 by leo