Skip to content

abdullah12022skipq/E-Commerce-Api

Repository files navigation

E-commerce API

This is an E-commerce API built using Node.js and Express. The API provides functionalities for product management, cart management, order placement, authentication, and authorization. Data is persisted using Supabase.

Table of Contents

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/ecommerce-api.git
    cd ecommerce-api
  2. Install dependencies:

    npm install
  3. Set up environment variables:

    Create a .env file in the root of the project and add the following variables:

    SUPABASE_URL=your-supabase-url
    SUPABASE_KEY=your-supabase-key
    JWT_SECRET=your-jwt-secret
  4. Initialize the database schema in Supabase:

    Create the necessary tables in your Supabase project:

    • Users
    • Products
    • Carts
    • CartItems
    • Orders
    • OrderItems

Usage

  1. Start the server:

    npm start
  2. The API will be available at http://localhost:3000.

OR

Base URL

The API is deployed on Railway Cloud and can be accessed at: https://e-commerce-api-production-dc2f.up.railway.app

API Endpoints

User Registration

POST /auth/register

User Registration

User Login

POST /auth/login

User Login

Create a New Product

POST /products

Create Product

Retrieve All Products

GET /products

Retrieve Products

Update a Product

PUT /products/:id

Update Product

Delete a Product

DELETE /products/:id

Delete Product

Create a New Cart

POST /carts

Create Cart

Add a Product to the Cart

POST /carts/:cartId/products

Add Product to Cart

Remove a Product from the Cart

DELETE /carts/:cartId/products/:productId

Remove Product from Cart

Retrieve Cart Contents

GET /carts/:cartId

Retrieve Cart Contents

Place an Order

POST /orders/:cartId

Place Order

Retrieve Order Details

GET /orders/:orderId

Retrieve Order Details

Error Handling

The API uses centralized error handling middleware to return appropriate HTTP status codes and error messages for different scenarios. Custom error classes are used to represent different error types.

Swagger Documentation

The API is documented using Swagger. You can access the Swagger UI at http://localhost:3000/api-docs.

Deployment

Docker Deployment

  1. Build the Docker image:

    docker build -t ecommerce-api .
  2. Run the Docker container:

    docker run -p 3000:3000 -d ecommerce-api

Railway Deployment

  1. Push the Docker image to a container registry.
  2. Set up a new project on Railway.
  3. Configure environment variables on Railway.
  4. Deploy the Docker image from the container registry.

Contributing

Contributions are welcome! Please open an issue or submit a pull request with your improvements.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published