Last active
May 8, 2018 19:45
-
-
Save colinskow/09cd09162bd652fa4b712030b7109179 to your computer and use it in GitHub Desktop.
Passing parameters to an API
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('/api/todo/:key', (req, res, next) => { | |
todos.findOne({ key: req.params.key }) | |
.then(result => { | |
if (!result) { | |
return next({ status: 404, message: 'not found' }); | |
} | |
res.status(200).json(result); | |
}) | |
.catch(err => { | |
return next({ status: 500, message: err.message }); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment