I am using the restify 2.8.4.
Understood that named parameter with regular expression is not supported in Mixing regex and :params in route #247
Instead of cobble both logics into one block.
server.get ('/user/:id', function (req, res, next) {
var id = req.params.id;
// check with isNaN()
// if string do this
// if number do that
}
I prefer below code structure:
//hit this route when named param is a number
server.get (/user\/:id(\\d+)/, function (req, res, next) {
var id = req.params.id;
// do stuff with id
}
//hit this route when named param is a string
server.get (/user\/:name[A-Za-z]+/, function (req, res, next) {
var name = req.params.name;
// do stuff with name
}
Is there a way I can split them into two separate concerns?