Created
April 13, 2017 19:05
-
-
Save sean3z/94af90df7ad2aaa9f98c017039784d6b to your computer and use it in GitHub Desktop.
Example Restify route
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
app.get('/hello/:name/:age([0-9]+)/:cool(true|false)', (req, res, next) => { | |
let {name, age, cool} = req.params; | |
cool = (cool === 'true'); | |
age = parseInt(age); | |
if (cool) { | |
res.send(`You're a cool ${age} year old, ${name}`); | |
} else { | |
res.send(`${name}, we need to talk about your coolness.`); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment