Skip to content

Instantly share code, notes, and snippets.

@amandeepmittal
Created October 4, 2018 12:35
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 amandeepmittal/3da6f1d46d60b13f02c505b2132d4a3e to your computer and use it in GitHub Desktop.
Save amandeepmittal/3da6f1d46d60b13f02c505b2132d4a3e to your computer and use it in GitHub Desktop.
// books.js
router.get('/:id', (ctx, next) => {
let getCurrentBook = books.filter(function(book) {
if (book.id == ctx.params.id) {
return true;
}
});
if (getCurrentBook.length) {
ctx.body = getCurrentBook[0];
} else {
ctx.response.status = 404;
ctx.body = 'Book Not Found';
}
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment