[JITERA] Add PATCH /books/:id route to bookRoutes
Created by: chi-jitera
Overview
This pull request introduces a new PATCH endpoint for updating specific fields of a book resource. The new route is added to the existing book routes to enhance the API's functionality.
Changes
-
Updated
/routes/bookRoutes.js:- Added the PATCH route for
/books/:idusing thebookController.patchBookmethod. - The new route is placed logically between the PUT and DELETE routes to maintain a clear structure for HTTP methods related to resource updates.
- Added the PATCH route for
Code Changes
const express = require('express');
const bookController = require('../controllers/bookController');
const router = express.Router();
router.post('/books', bookController.createBook);
router.get('/books', bookController.getAllBooks);
router.get('/books/search', bookController.searchBooks);
router.get('/books/:id', bookController.getBookById);
router.put('/books/:id', bookController.updateBook); // Added PATCH route
router.patch('/books/:id', bookController.patchBook); // New PATCH route
router.delete('/books/:id', bookController.deleteBook);
module.exports = router;
This addition allows clients to partially update book resources, improving the flexibility of the API.