This is an e-commerce API built with Node.js and Express.js, utilizing Supabase for data storage. The API supports product management, cart management, order placement, and user authentication.
API documentation is available at /api-docs
.
- Clone the repository:
git clone https://github.com/usama739/Ecommerce-API.git cd ecommerce-api
- Install dependencies:
npm install
- Create a .env file in the root directory and add your environment variables:
SUPABASE_URL=your_supabase_url SUPABASE_KEY=your_supabase_key
- Start the server:
npx nodemon server.js
Once the server is running, you can use tools like Postman to interact with the API endpoints.
-
Register a New User
URL: POST
/api/auth/register
Description: Registers a new user.
-
Login
URL: POST
/api/auth/login
Description: Logs in a user.
-
Create a New Product
URL: POST
/api/products
Description: Creates a new product.
-
Retrieve or Filter Products by Category
URL: GET
/api/products?category=CategoryName
Description: Retrieves products filtered by category.
-
Update a Product
URL: PUT
/api/products/:id
Description: Updates the details of an existing product.
-
Delete a Product
URL: DELETE
/api/products/:id
Description: Deletes a product.
Note: Only authenticated users can access and modify their cart information.
-
Create a New Cart
URL: POST
/api/cart
Description: Creates a new cart for a user.
-
Add Product to Cart
URL: POST
/api/cart/add
Description: Adds a product to the user's cart with a specified quantity.
-
Remove Product from Cart
URL: POST
/api/cart/remove
Description: Removes a product from the user's cart.
It will generate an error if the user is not authenticated.
Product will be removed if authenticated user makes a request
-
Get Cart Contents
URL: GET
/api/cart/:userId
Description: Retrieves the contents of the user's cart.
Note: Only authenticated users can access and modify their order information.