# Deleting A Book Listing By ID - Planning

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

## 1 - Route Name

Finally, our final API endpoint. For the delete a book by ID, it will be very similar to updating.

We'll just use `DELETE` instead of `PUT` as our method verb of choice.

`DELETE /api/v1/books/:id`

## 2 - Input Request

None.

## 3 - Middleware

This will be the exact same as the last section.

For the first layer, we'll be reusing our `isAuthenticated` helper that will protect us from unauthenticated user from accessing this endpoint.

For the second layer, we'll be reusing our `bookPermission` helper to verify that the requested book ID exists and that the currently authenticated user is in fact the owner of it.

## 4 - Validation

None.

## 5 - Domain

Just like the last section, we'll built on top of the previous section and use the **bookModel**.

We'll also need some sort of way to make a query to the database in order to find the existing book and delete it, so we'll use the `bookRepository` layer and add the method `deleteById()` to do so.

**bookRepository**

* `deleteById()`

On top of that, our controller will call a service to `deleteBookById()`, in this case, it will be the `bookService` which will use the `bookRepository` layer.

**bookService**

* `deleteBookById()`

## 6 - Events

None.

## 7 - Response

Again, very similar to the previous section, except there will be 3 possible responses that can be output with this endpoint.

The first is the authentication middleware that we'll be reusing.

```json
{
  "status": "error",
  "code": 401,
  "message": "Access denied: you must be logged in to access this API endpoint.",
  "data": null,
  "errors": ["You must be logged in."]
}
```

The second is whether or not the client has inputted an existing book ID.

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

The third is the successful scenario. Do keep in mind that since we are using a `DELETE` request, so won't be returning any representation back.

```json
{
  "status": "success",
  "code": 200,
  "message": "The book has successfully been deleted.",
  "data": {},
  "errors": null
}
```


---

# 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-9/5-deleting-a-book-listing-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.
