Skip to content
This guide is a work in progress and will be updated as the project evolves

API — Users Book Operations

We’re now working with the User Library concept. This is where a user is able to effectively “check-out” a book from the system library and add their review and rating.

Add Book to User Library (with review and rating)

This endpoint provides functionality to add a system library book to the user’s library along with their specific rating and review.

  1. Perform a POST request:

    Terminal window
    curl --location 'http://localhost:8080/users/1c529433-063f-40c2-8dba-4d5a8197fd5b/books/f89ae585-599f-44cf-ae4a-9159250a1d12' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwi....' \
    --data '{
    "rating": 5,
    "review": "This is a review"
    }'
  2. This should provide a response like:

    {
    "book": {
    "bookID": "f89ae585-599f-44cf-ae4a-9159250a1d12",
    "title": "My Awesome Book",
    "isbn": "978-1-1242-4798-4",
    "pages": 500,
    "plot": "This is a plot",
    "cover": "cover.jpg",
    "datePublished": "2022-08-29",
    "dateAdded": "2024-05-24T18:25:23.837749",
    "dateUpdated": "2024-05-24T18:25:23.837763"
    },
    "review": "This is a review",
    "rating": 5
    }
  3. This returns a book object containing its core details as well as the review and rating values the user created.

Add Book to User Library (with rating only)

This endpoint provides functionality to add a system library book to the user’s library along with their specific rating. Notice that the user is not required to provide a review, but a rating is required. The review can be added at a later stage.

  1. Perform a POST request:

    Terminal window
    curl --location 'http://localhost:8080/users/1c529433-063f-40c2-8dba-4d5a8197fd5b/books/f89ae585-599f-44cf-ae4a-9159250a1d12' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwi....' \
    --data '{
    "rating": 5
    }'
  2. This should provide a response like:

    {
    "book": {
    "bookID": "f89ae585-599f-44cf-ae4a-9159250a1d12",
    "title": "My Awesome Book",
    "isbn": "978-1-1242-4798-4",
    "pages": 500,
    "plot": "This is a plot",
    "cover": "cover.jpg",
    "datePublished": "2022-08-29",
    "dateAdded": "2024-05-24T18:25:23.837749",
    "dateUpdated": "2024-05-24T18:25:23.837763"
    },
    "rating": 5
    }
  3. This returns a book object containing its core details as well as the rating values the user created.

Update a User’s Book (with rating only)

This endpoint provides functionality to update an existing book item the user has added to their library. In this case only the mandatory property is supplied: rating.

  1. Perform a PUT request:

    Terminal window
    curl --location --request PUT 'http://localhost:8080/users/1c529433-063f-40c2-8dba-4d5a8197fd5b/books/f89ae585-599f-44cf-ae4a-9159250a1d12' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwi....' \
    --data '{
    "rating": 8
    }'
  2. There is no response body, and the HTTP status code is HTTP 204 No Content

  3. You can run the Get Users Book by UserID and BookID request to see the difference. The response will show the updated rating value.

    {
    "book": {
    "bookID": "f89ae585-599f-44cf-ae4a-9159250a1d12",
    "title": "My Awesome Book",
    "isbn": "978-1-1242-4798-4",
    "pages": 500,
    "plot": "This is a plot",
    "cover": "cover.jpg",
    "datePublished": "2022-08-29",
    "dateAdded": "2024-05-24T18:25:23.837749",
    "dateUpdated": "2024-05-24T18:25:23.837763"
    },
    "rating": 8
    }

Update a User’s Book (with rating and review)

This endpoint provides functionality to update an existing book item the user has added to their library. In this case the rating and review are both updated.

  1. Perform a PUT request:

    Terminal window
    curl --location --request PUT 'http://localhost:8080/users/1c529433-063f-40c2-8dba-4d5a8197fd5b/books/f89ae585-599f-44cf-ae4a-9159250a1d12' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwi....' \
    --data '{
    "rating": 6,
    "review": "this is a review update"
    }'
  2. There is no response body, and the HTTP status code is HTTP 204 No Content

  3. You can run the Get Users Book by UserID and BookID request to see the difference. The response will show the updated rating value.

    {
    "book": {
    "bookID": "f89ae585-599f-44cf-ae4a-9159250a1d12",
    "title": "My Awesome Book",
    "isbn": "978-1-1242-4798-4",
    "pages": 500,
    "plot": "This is a plot",
    "cover": "cover.jpg",
    "datePublished": "2022-08-29",
    "dateAdded": "2024-05-24T18:25:23.837749",
    "dateUpdated": "2024-05-24T18:25:23.837763"
    },
    "review": "this is a review update",
    "rating": 6
    }

Get Users Book by UserID and BookID

This endpoint provides functionality to retrieve a specific book for a user from the user’s library.

  1. Perform a GET request:

    Terminal window
    curl --location 'http://localhost:8080/users/1c529433-063f-40c2-8dba-4d5a8197fd5b/books/f89ae585-599f-44cf-ae4a-9159250a1d12' \
    --header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwi....' \
  2. This should provide a response like:

    {
    "book": {
    "bookID": "f89ae585-599f-44cf-ae4a-9159250a1d12",
    "title": "My Awesome Book",
    "isbn": "978-1-1242-4798-4",
    "pages": 500,
    "plot": "This is a plot",
    "cover": "cover.jpg",
    "datePublished": "2022-08-29",
    "dateAdded": "2024-05-24T18:25:23.837749",
    "dateUpdated": "2024-05-24T18:25:23.837763"
    },
    "review": "this is a review update",
    "rating": 6
    }

Get all Users Books by UserID

This endpoint provides functionality to retrieve all the associated books for a user from the user’s library.

  1. Perform a GET request:

    Terminal window
    curl --location 'http://localhost:8080/users/1c529433-063f-40c2-8dba-4d5a8197fd5b/books' \
    --header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwi....' \
  2. This should provide a response like:

    [
    {
    "book": {
    "bookID": "f89ae585-599f-44cf-ae4a-9159250a1d12",
    "title": "My Awesome Book",
    "isbn": "978-1-1242-4798-4",
    "pages": 500,
    "plot": "This is a plot",
    "cover": "cover.jpg",
    "datePublished": "2022-08-29",
    "dateAdded": "2024-05-24T18:25:23.837749",
    "dateUpdated": "2024-05-24T18:25:23.837763"
    },
    "review": "this is a review update",
    "rating": 6
    }
    ]

Remove Book from User’s Library

This endpoint provides functionality to remove a book from the user’s library.

  1. Perform a DELETE request:

    Terminal window
    curl --location --request DELETE 'http://localhost:8080/users/1c529433-063f-40c2-8dba-4d5a8197fd5b/books/f89ae585-599f-44cf-ae4a-9159250a1d12' \
    --header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwi....'
  2. There is no response body, and the HTTP status code is HTTP 204 No Content

  3. Run the Get all Users Books by UserID request again to see the difference

    [ ]
  4. As can be seen in the response above, the book we added earlier was removed. The response is an empty array: [ ], which denotes that this user does not have any books in their user library.

Summary

Endpoints covered in this guide are as follows:

  • POST /users/<userID>/books/<bookID>
    • Add book to user library by making use of the userID and bookID values.
  • PUT /users/<userID>/books/<bookID>
    • Update book in user library by making use of the userID and bookID values.
  • GET /users/<userID>/books/<bookID>
    • Get a specific book along with the user’s rating and review from the user’s library by making use of the userID and bookID values.
  • GET /users/<userID>/books
    • Get all the books from the user’s library along with the rating and review for each book by making use of the userID value.
  • DELETE /users/<userID>/books/<bookID>
    • Remove book from the user’s library by making use of both the userID and the bookID values.