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.
-
Perform a
POST
request: -
This should provide a response like:
-
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.
-
Perform a
POST
request: -
This should provide a response like:
-
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.
-
Perform a
PUT
request: -
There is no response body, and the HTTP status code is
HTTP 204 No Content
-
You can run the Get Users Book by UserID and BookID request to see the difference. The response will show the updated
rating
value.
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.
-
Perform a
PUT
request: -
There is no response body, and the HTTP status code is
HTTP 204 No Content
-
You can run the Get Users Book by UserID and BookID request to see the difference. The response will show the updated
rating
value.
Get Users Book by UserID and BookID
This endpoint provides functionality to retrieve a specific book for a user from the user’s library.
-
Perform a
GET
request: -
This should provide a response like:
Get all Users Books by UserID
This endpoint provides functionality to retrieve all the associated books for a user from the user’s library.
-
Perform a
GET
request: -
This should provide a response like:
Remove Book from User’s Library
This endpoint provides functionality to remove a book from the user’s library.
-
Perform a
DELETE
request: -
There is no response body, and the HTTP status code is
HTTP 204 No Content
-
Run the Get all Users Books by UserID request again to see the difference
-
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
andbookID
values.
- Add book to user library by making use of the
PUT /users/<userID>/books/<bookID>
- Update book in user library by making use of the
userID
andbookID
values.
- Update book in user library by making use of the
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
andbookID
values.
- Get a specific book along with the user’s rating and review from the user’s library by
making use of the
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.
- Get all the books from the user’s library along with the rating and review for each book by
making use of the
DELETE /users/<userID>/books/<bookID>
- Remove book from the user’s library by making use of both the
userID
and thebookID
values.
- Remove book from the user’s library by making use of both the