A robust and scalable RESTful API for managing an e-commerce platform. This API supports features such as user authentication, product management, order processing, and more. Built using Node.js, Express, and MongoDB, it follows modern development practices for maintainability and performance.
-
User Management:
- User registration and login with JWT-based authentication.
- Role-based access control (e.g., admin and customer roles).
-
Product Management:
- CRUD operations for products.
- Product categorization and filtering.
-
Order Management:
- Create, update, and view orders.
- Track order status.
-
Cart System:
- Add, remove, and update cart items.
- Persistent carts for logged-in users.
-
Secure Payments:
- Integration with payment gateways (e.g., Stripe, PayPal).
-
Admin Dashboard:
- Manage users, products, and orders.
- Backend: Node.js, Express.js
- Database: MongoDB (with Mongoose ORM)
- Authentication: JSON Web Tokens (JWT)
- Middleware: Express middleware for validation, error handling, and logging
- Others:
bcryptjs
for password hashing.morgan
for logging.dotenv
for environment variable management.
Ensure you have the following installed on your machine:
-
Clone the repository:
git clone https://github.com/Jhaemis-hack/E-Commerce-Restful-API.git cd E-Commerce-Restful-API
-
Install dependencies:
npm install
-
Set up environment variables:
- Create a
.env
file in the root directory. - Add the following environment variables:
PORT=3000 MONGO_URI=mongodb://localhost:27017/ecommerce JWT_SECRET=your_secret_key
- Create a
-
Start the server:
npm start
The API will run at
http://localhost:3000
.
Method | Endpoint | Description |
---|---|---|
POST | /auth/register |
Register a new user. |
POST | /auth/login |
Log in and get a token. |
Method | Endpoint | Description |
---|---|---|
GET | /products |
Get all products. |
POST | /products |
Add a new product (admin). |
PUT | /products/:id |
Update product details. |
DELETE | /products/:id |
Delete a product (admin). |
Method | Endpoint | Description |
---|---|---|
GET | /user |
View cart items. |
POST | /user/add |
Add a product to the cart. |
PUT | /user/:id |
Update cart item quantity. |
DELETE | /user/:id |
Remove an item from the cart. |
Method | Endpoint | Description |
---|---|---|
GET | /orders |
View all orders (admin only). |
POST | /orders |
Create a new order. |
PUT | /orders/:id |
Update order status (admin). |
E-Commerce-Restful-API/
├── models/ # MongoDB schemas for users, products, orders, etc.
├── routes/ # API route definitions
├── controllers/ # Controller logic for handling requests
├── middleware/ # Custom middleware (e.g., authentication, validation)
├── config/ # Database and environment configuration
├── .env # Environment variables
├── package.json # Dependency management
└── app.js # Main server entry point
-
Run tests (if implemented):
npm test
-
Use tools like Postman or Thunder Client to test endpoints manually.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature/bug fix.
- Submit a pull request with a detailed description of your changes.
This project is licensed under the MIT License. See the LICENSE
file for details.