This project provides a Django REST API for an e-commerce platform, supporting CRUD operations (Create, Read, Update, Delete) for products. It includes user authentication for secure access to product data manipulation only (update, delete and create). But user can read for data without auth token.
- Secure authentication using Django Rest Framework Authentication (JWT Toke)
- Full CRUD support for managing products
- Supports multiple images uploads for products
- API endpoints GET, POST, PUT, and DELETE
- Lightweight and fast, perfect for small to medium-scale e-commerce platforms
Use the provided authentication mechanism to obtain tokens.
- Register User:
- Fill these 3 fields
URL: POST to Base_URL/api/auth/register
username #PK
email
password
- Login User:
POST to Base_URL/api/auth/login
username
password
On successful login, you will receive an authentication token to be used in the header for subsequent write requests.
- Get All Products:
GET request to Base_URL/api/products
- Get a Single Product:
GET request to Base_URL/api/product/product_id
- Create Product (Authenticated):
POST request to Base_URL/api/product/products
# with title, description, num_of_prod_on_stock, price, uploaded_images
# With Auth token
- Update Product (Authenticated):
PUT request to Base_URL/api/product/id_of_item
# with title, description, num_of_prod_on_stock, price, uploaded_images
# With Auth token
- Delete Product (Authenticated):
DELETE request to Base_URL/api/product/delete/id_of_item
# With Auth token
- Clone the project
git clone https://github.com/abdulawalarif/ecommerce_backend_DRF.git
- Go to the project directory
cd ecommerce_backend_DRF && cd ecommerce_backend
- Create a virtual environment
python3 -m venv .ecom_env
- Activate the virtual environment
source .ecom_env/bin/activate
- Install all the packages
pip install -r requirements.txt
- go to the ecommerce_backend/settings.py and change the databse to Sqlite
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
Or you can crate a SQL if you want to.
- Now create migration for your database
python manage.py makemigrations
- Now Create Tables and Fields for the database
python manage.py migrate
- Run the project
python manage.py runserver
Now fill some data first with this URL POST request
It's a good starter boilerplate, for an ecommerce app, Create models for categories and user's follow a good design architecture and make sure to Normalize the datababse for preventing overload or duplication of same data in multiple places.
If you found an issue or would like to submit an improvement to this project, please submit an issue using the issues tab above. If you would like to submit a PR with a fix, reference the issue you created!
- Update method do no delete images it just add new images with existing image list.