Last active
December 22, 2015 20:29
-
-
Save L1fescape/6527231 to your computer and use it in GitHub Desktop.
Required params for NodeJS. Basic working example, needs improvements.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function required(params) { | |
return function (req, res, cb) { | |
if (params.every(function (elem) { return req.body.hasOwnProperty(elem); })) | |
cb(); | |
else | |
res.send(400, {status:400, message: 'Missing required body parameters.'}); | |
}; | |
}; | |
/* | |
* Routes | |
*/ | |
// GET Some 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