This project implements an e-commerce API using Node.js, Express.js, Sequelize, and PostgreSQL. The API provides endpoints for user registration, authentication, product and category listing, cart management, order processing, and more.
- User registration and authentication using JSON Web Tokens (JWT)
- Category listing and product listing with essential details
- Product details retrieval
- Cart management: add, view, update, and remove items from the cart
- Order placement and order history retrieval
- Error handling and meaningful error messages
-
Clone the repository:
git clone https://github.com/abinetha/e-commerce-api.git
-
Navigate to the project directory:
cd e-commerce-api
-
Install dependencies:
npm install
-
Set up PostgreSQL database and configure the connection in
config.js
. -
Start the server:
node API.js
-
The server will start running on http://localhost:3000 by default.
-
Register a new user:
- Send a POST request to
/register
with JSON body containingusername
andpassword
.
- Send a POST request to
-
Login:
- Send a POST request to
/login
with JSON body containingusername
andpassword
. Upon successful login, you'll receive a JWT token.
- Send a POST request to
-
Category Listing:
- Send a GET request to
/categories
to retrieve a list of categories.
- Send a GET request to
-
Product Listing:
- Send a GET request to
/products/:categoryId
to retrieve a list of products based on category ID.
- Send a GET request to
-
Product Details:
- Send a GET request to
/product/:productId
to retrieve detailed information about a specific product.
- Send a GET request to
-
Cart Management:
- Add product to cart: Send a POST request to
/cart
with JSON body containingproductId
andquantity
. - View cart: Send a GET request to
/cart
to retrieve the user's cart. - Update cart item: Send a PUT request to
/cart/:productId
with JSON body containingquantity
to update the quantity of a product in the cart. - Remove item from cart: Send a DELETE request to
/cart/:productId
to remove a product from the cart.
- Add product to cart: Send a POST request to
-
Order Placement:
- Send a POST request to
/orders
to place an order using the products in the user's cart.
- Send a POST request to
-
Order History:
- Send a GET request to
/orders
to retrieve the order history for the authenticated user.
- Send a GET request to
-
Order Details:
- Send a GET request to
/orders/:orderId
to retrieve detailed information about a specific order.
- Send a GET request to
The API endpoints are documented using Swagger. You can view the API documentation by accessing the following URL in your browser after starting the server:
http://localhost:3000/api-docs