Skip to content

Instantly share code, notes, and snippets.

@kieranbarker
Created March 9, 2026 10:02
Show Gist options
  • Select an option

  • Save kieranbarker/ecd057142af784ffe54fb5676702937a to your computer and use it in GitHub Desktop.

Select an option

Save kieranbarker/ecd057142af784ffe54fb5676702937a to your computer and use it in GitHub Desktop.
app.patch("/books/:id", (req, res) => {
// Attempt to find the book.
let book = findBook.get({ id: req.params.id });
// If the book doesn't exist, send an error.
if (!book) {
res.status(404).json({ errors: ["Book not found"] });
return;
}
// Otherwise, update the book.
const updates = { ...book, ...req.body };
updateBook.run(updates);
book = findBook.get({ id: req.params.id });
res.status(200).json(book);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment