This is a CRUD REST API for managing books, built with Express.js, Node.js, and MongoDB.
- Create a new book
- Retrieve all books
- Retrieve a single book by ID
- Update a book's details
- Delete a book
- Node.js
- Express.js
- MongoDB
- Mongoose
- dotenv
-
Clone the repository:
git clone https://github.com/mohamedfo17/CRUD-Rest-API cd CRUD-Rest-API -
Install dependencies:
npm install
-
Create a
.envfile and add your MongoDB connection string:MONGO_URI=your_mongodb_connection_string PORT=3000
-
Start the server:
nodemon start
- Endpoint:
POST /books - Description: Adds a new book to the database.
- Request Body:
{ "title": "Book Title", "author": "Author Name", "publishedYear": 2024 }
- Endpoint:
GET /books - Description: Retrieves a list of all books.
- Endpoint:
GET /books/:id - Description: Retrieves a book by its ID.
- Endpoint:
PUT /books/:id - Description: Updates an existing book's details.
- Request Body: (Provide the fields you want to update)
{ "title": "Updated Title", "author": "Updated Author" }
- Endpoint:
DELETE /books/:id - Description: Removes a book from the database.