Retrieving A Book By ID - Planning
Last updated
Last updated
Refer back to section for the API endpoint specifications.
Much like how we planned out the URI for retrieving all books, retrieving a single book is not too far off from that. From the specifications, it seems like this will be a GET
request that will fetch a single book by its ID. We can refer back to the sections under chapter 3 for guidelines, specifically the sections and .
The following URI should suffice.
GET /api/v1/books/:id
Similar to retrieving all books, there are none.
Similar to retrieving all books, there are none.
Similar to retrieving all books, there are none.
Similar to the retrieval of all books, we will be using the same 3 entities to orchestrate our domain logic.
bookModel
bookRepository
bookService
We will definitely use the bookRepository
and get it a method something like getById()
.
In the bookService
, we would want to have a method as well, perhaps, getBookById()
. Also, remember that we want to do some sort of validation to check if the book we are trying to retrieve exists. Recall that we must return a 404 in our response to indicate that a book with the specified ID by the client does not exist.
Similar to retrieving all books, there are none.
There are 2 types of responses that could possibly return from this endpoint.
The first is the book with the specified ID if it does exist in the database.
The second is a message indicating to the client that the book with the specified ID does not exist.