POST /updateFavourite/:id
This toggles the favourited property of a book
Endpoint URL
http://127.0.0.1:8080/api/updateFavourite/:idPath parameters
Name
Type
Description
JSON body parameters
Name
Type
Description
Example code
favouriteButton.addEventListener("click", async () => {
// Toggle the 'favourited' property of the book
book.favourited = !book.favourited;
// Send a POST request to the server-side script
try {
const response = await fetch(`/api/updateFavourite/${book._id}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ favourited: book.favourited }),
});
const data = await response.json();
console.log("Success:", data.message);
} catch (error) {
console.error("Error:", error);
}
});Example response
Response fields
Name
Type
Description
Last updated