Skip to content

[JITERA] Enhance Book API: Add PATCH Method for Updating Book Details

Created by: chi-jitera

Overview

This pull request introduces support for the PATCH method in the existing book API, allowing users to update book details by their ID. Previously, the API only supported the DELETE method for removing books.

Changes

  1. Added PATCH Method Handling:

    • A condition was added to handle the PATCH method in the API handler.
  2. Book ID Validation:

    • The book ID is extracted from the request query and validated to ensure it is a valid string. If the ID is invalid or missing, a 400 error response is returned.
  3. Data Extraction for Update:

    • The data to be updated is extracted from the request body. If the update data is invalid or missing, a 400 error response is returned.
  4. Book Lookup and Update:

    • The book is searched in the in-memory data store by its ID. If the book is not found, a 404 error response is returned. If found, the book details are updated using Object.assign.
  5. Success Response:

    • A success response is returned with a message indicating the book was updated successfully, along with the updated book details.

This enhancement improves the API's functionality, making it more versatile for managing book records.

Merge request reports