Retrieving All Books - Planning
Refer back to Chapter 6, The Bookstore API Endpoint Specifications, API Endpoint #5: Retrieve All Book Listings section for the API endpoint specifications.
1 - Route Name
From the specification, it seems like this will be a GET
request that will fetch a collection of books. We can refer back to the sections under chapter 3 for guidelines to follow, specifically the sections Method Verbs and URI Design.
The following URI should suffice.
GET /api/v1/books
2 - Input Request
Since this is a GET
request, there won't be any input request or payload from the client.
3 - Middleware
This is a public URI, so there really is no need for any middleware.
4 - Validation
Again, since this is just a simple GET
request, there won't be any validation needed.
5 - Domain
From the specifications, it looks like we will need the following book entity in our domain layer.
bookModel
title
description
price
author
datePublished
We will also need some sort of way to query the database to be able to retrieve all the books, getAllBooks()
will be the method we'd call.
bookRepository
getAll()
On top of that, our controller will call a service, in this case, it will be the bookService
which will retrieve all of the books in our database.
bookService
getAllBooks()
This is a rough outline of how we are going to be implementing these functions, we'll take a deeper dive at the implementations in the next section of this chapter.
6 - Events
Judging from the specifications, there doesn't seem to be any events, so we'll leave this blank as well.
7 - Response
As mentioned previous, we will be "Using a Consistently Wrapped Response".
We'll be adding in these fields:
title
description
price
author
datePublished
for each of our book listings.
Last updated