DELETE /books/:id
This will delete a book from the database, the book deleted will be determined by the ID parameter
Endpoint URL
http://127.0.0.1:8080/api/books/:idPath parameters
Name
Type
Description
Example code
// Add an event listener to delete the book when clicked
deleteButton.addEventListener("click", async () => {
// Ask if the user is sure they want to delete the book
const confirmDelete = window.confirm("Are you sure you want to delete this book?");
// If the user clicked OK, delete the book
if (confirmDelete) {
try {
const response = await fetch(`/api/books/${book._id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
} else {
books.removeChild(bookContainer); // Remove the book from the library
const data = await response.text();
console.log("Success:", data);
}
} catch (error) {
console.error("Error:", error);
}
}
});Example response
Response fields
Name
Type
Description
Last updated