[JITERA] Implement DELETE /books/:id API Endpoint
Created by: chi-jitera
Overview
This pull request introduces a new API endpoint for deleting a book by its ID in a Next.js application. The implementation follows the Next.js conventions for API routes and includes necessary validations and response handling.
Changes
-
File Created:
src/pages/api/books/[id].ts- This file implements the DELETE
/books/:idAPI endpoint.
- This file implements the DELETE
-
HTTP Method Validation:
- The API checks if the request method is DELETE. If not, it responds with a
405 Method Not Allowedstatus.
- The API checks if the request method is DELETE. If not, it responds with a
-
ID Validation:
- The API extracts the book ID from the request query and validates it. If the ID is missing or invalid, it responds with a
400 Bad Requeststatus.
- The API extracts the book ID from the request query and validates it. If the ID is missing or invalid, it responds with a
-
Book Deletion Logic:
- The API searches for the book in a dummy in-memory data store. If the book is not found, it responds with a
404 Not Foundstatus. - If the book is found, it is removed from the store, and a success message is returned with a
200 OKstatus.
- The API searches for the book in a dummy in-memory data store. If the book is not found, it responds with a
-
Response Codes:
- The implementation adheres to the specified response codes and messages for different scenarios.
Notes
- The current implementation uses a dummy in-memory data store. It is recommended to replace this with actual database access logic as per your project's architecture.
- No authentication is required for this endpoint, as specified in the requirements.
Please review the changes and let me know if any adjustments are needed!