- Node.js
- MySQL
- Npm
-
Clone the repository:
git clone https://github.com/yourusername/books-crud-api.git cd books-crud-api
-
Install Dependencies
npm install
-
Configure the Database and Table
CREATE DATABASE express_mysql; USE express_mysql; CREATE TABLE Books (id INT AUTO_INCREMENT PRIMARY KEY, title VARCHAR(100) NOT NULL, author VARCHAR(100) NOT NULL);
-
Start application
nodemon .
-
FIND ALL
- URL: /books
- METHOD: Get
- Response :
[ { "id": 2, "title": "book 1", "author": "author X" } ]
-
FIND BY ID
- URL: /books/{id}
- METHOD: Get
- Response :
{ "id": 2, "title": "book 1", "author": "author X" }
-
DELETE BOOK
- URL: /books/{id}
- METHOD: Delete
- Response :
{ "message": "Book deleted successfully" }
-
ADD BOOK
- URL: /books
- METHOD: Post
- Request Body:
{ "title": "new book", "author": "author X" }
- Response:
{ "id": 7, "title": "new book", "author": "author X" }
-
UPDATE BOOK
- URL: /books/{id}
- METHOD: Put
- Request Body:
{ "title": "new book update", "author": "author A" }
- Response:
{ "message": "Book updated successfully" }