# Retrieving A Book By ID - Planning

Refer back to [*Chapter 6, The Bookstore API Endpoint Specifications, API Endpoint #6: Retrieve a Book Listing*](/part-3/chapter-6/1-the-bookstore-api-endpoint-specifications.md#api-endpoint-5-retrieve-all-book-listings) section for the API endpoint specifications.

## 1 - Route Name

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 [*Method Verbs*](/part-2/chapter-3/3-method-verbs.md) and [*URI Design*](/part-2/chapter-3/2-uri-design.md).

The following URI should suffice.

`GET /api/v1/books/:id`

## 2 - Input Request

Similar to retrieving all books, there are none.

## 3 - Middleware

Similar to retrieving all books, there are none.

## 4 - Validation

Similar to retrieving all books, there are none.

## 5 - Domain

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.

## 6 - Events

Similar to retrieving all books, there are none.

## 7 - Response(s)

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.

```json
{
    "status": "success",
    "code": 200,
    "message": "Here is the book with the specified ID."
    "data": {
       "id": "61f88350745d83158f3c746d",
       "title": "Harry Potter and the Goblet of Fire",
       "description": "Mint condition, but will negotiate",
       "price": 99,
       "author": "J.K. Rowling",
       "datePublished": "Sun Oct 10 2021 23:56:34 GMT-0400"
    },
    "errors": null
}
```

The second is a message indicating to the client that the book with the specified ID does not exist.

```json
{
    "status": "error",
    "code": 404,
    "message": "That book with the specified ID does not exist."
    "data": null,
    "errors": [
        "Book listing not found."
    ]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.restfulnode.com/part-3/chapter-7/3-retrieving-a-book-by-id-planning.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
