Skip to content

Instantly share code, notes, and snippets.

@colinskow
Last active May 8, 2018 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinskow/09cd09162bd652fa4b712030b7109179 to your computer and use it in GitHub Desktop.
Save colinskow/09cd09162bd652fa4b712030b7109179 to your computer and use it in GitHub Desktop.
Passing parameters to an API
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