POST /updateFavourite/:id

This toggles the favourited property of a book

Endpoint URL

http://127.0.0.1:8080/api/updateFavourite/:id

Path parameters

Name
Type
Description

id

integer

Unique identifier for each book

JSON body parameters

Name
Type
Description

favourited

Boolean

Whether or not you want to set the book to be a favourite or to remove its favourited status

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

message

string

A message to confirm or post an error, status of the POST request

Last updated