Skip to content

umerzzz900/ecommerce-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

E-Commerce REST API with Flask, MySQL, and JWT

==============================================

This is a full-featured E-commerce REST API built with Flask, MySQL, and JWT Authentication.

It supports user registration/login, product management, order placement, order tracking,

and payment handling for both admin and customer roles.


Features:


- User Registration & Login with Password Hashing

- Role-based Authentication (Admin/Customer)

- JWT Token Handling for Secure Routes

- Product CRUD Operations (Admin Only)

- Product Listing (All Users)

- Order Placement & Tracking

- Payment & Cancellation Handling

- MySQL Integration with flask_mysqldb


Setup Instructions:


1. Clone the Repository:

  git clone

  cd

2. (Optional) Create Virtual Environment:

  python -m venv venv

  source venv/bin/activate # On Windows: venv\Scripts\activate

3. Install Dependencies:

  pip install -r requirements.txt

4. Setup MySQL:

  - Ensure MySQL is installed and running.

  - Create a database named ecom and import mysql\_file.txt:

  mysql -u root -p < mysql_file.txt

5. Run the Application:

  python app.py

  The app will run on http://0.0.0.0:5000


JWT Authentication:


On successful login, a JWT token is returned. Include this token in the Authorization header:

  Authorization: Bearer <your_token_here>


API Endpoints:


| Method | Endpoint | Description | Access |

|--------|--------------------------|--------------------------------------------|------------|

| POST | /register | Register a new user | Public |

| POST | /login | User login | Public |

| GET | /users/ | View user info (Admin only) | Admin |

| GET | /products | List all products | All Users |

| POST | /products | Add new product | Admin |

| PUT | /products/ | Update product info | Admin |

| DELETE | /products/ | Delete product | Admin |

| GET | /products/ | Get product info | All Users |

| POST | /orders | Place new order | Logged In |

| GET | /orders/ | Track specific order | Admin/User |

| GET | /users//orders | List all orders by user | Admin/User |

| PUT | /orders//pay | Pay/Cancel order | Logged In |


Roles:


- **Admin:** Can view, add, update, delete products. Can view all users and all orders.

- **Customer:** Can view products, place orders, and manage their own orders.


Sample Admin/User Setup:


- Register a user via /register

- Then manually update their role in MySQL:

  UPDATE users SET role = 'admin' WHERE uid = 1;


License:


This project is free to use for learning and development purposes.


Contributions:


Feel free to fork and create pull requests.

About

Ecommerce Backend Rest Api Using Flask Framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages