This is a RESTful API for a Motorcycle Rental service. The API is built with Node.js, Express.js, MongoDB, and Mongoose.
- CRUD operations for Motorcycles
- Query for top 5 motorcycles based on rental fee
- Custom middleware to modify request query
- Joi validation for motorcycle data
- Winston logger for error handling and logging to a file
- Route for partial updates using HTTP PATCH method
- Clone the repository
- Run
npm install
to install all dependencies - Make sure MongoDB is running locally or set your MongoDB URI in
.env
file - Run
npm start
to start the application
-
Get Top 5 Motorcycles
GET /api/motorcycles/top-5
-
Get All Motorcycles
GET /api/motorcycles
-
Get a Motorcycle by ID
GET /api/motorcycles/:id
-
Create a new Motorcycle
POST /api/motorcycles
-
Update a Motorcycle by ID
PUT /api/motorcycles/:id
-
Partially Update a Motorcycle by ID
PATCH /api/motorcycles/:id
-
Delete a Motorcycle by ID
DELETE /api/motorcycles/:id
When using the PATCH route for partial updates, only the fields you want to update need to be provided in the request body. Joi validation is used to ensure data integrity.
Errors are logged using the winston module, with error messages stored both in the console and in a dedicated logfile.log
file.
urban1991
MIT License