Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Forked from L1fescape/reqParams.js
Last active December 22, 2015 20:29
Show Gist options
  • Save ajcrites/6527261 to your computer and use it in GitHub Desktop.
Save ajcrites/6527261 to your computer and use it in GitHub Desktop.
function required(params) {
return function (req, res, cb) {
params.every(function (elem) { return req.body.hasOwnProperty(elem); })
&& cb()
|| res.send(400);
};
};
/**
* Sample route
*/
app.get("/route", required(["user_string"]), function(req, res) {
var respObj = {}
user_string = req.body.user_string;
res.writeHead(200, {'content-type': 'application/json'});
res.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment