This is the backend API for an E-commerce . It allows users to manage products, orders, categories, review products, add products to wishlist and user authentication. The project is built using Django and Django REST Framework.
Follow these steps to set up the development environment:
-
Create a virtual environment: In your project folder, run the following command to create a virtual environment:
python -m venv env
-
Install the Django Rest Framework: In your project folder, run the following command to install DRF:
pip install djangorestframework
-
Package for Securing Data:
To keep sensitive data out of the source code, install
python-decouple
:pip install python-decouple
-
Package for filtering:
In your project folder, run the following command to install to allows users to filter querysets:
pip install django-filter
-
Package for Mysql:
In your project folder, run the following command used in Python database connector to MySQL:
pip install mysqlclient
-
Create a new Django project: Create a django project
django-admin startproject product_api
-
Create a new Django app: Create a new Django app
python manage.py startapp product python manage.py startapp order python manage.py startapp user
-
Add the app to project: Open product_api/settings.py and add 'products' to the INSTALLED_APPS list. INSTALLED_APPS = [ 'rest_framework', # Django REST Framework 'products', # Your app ]
-
Run the development server: Run the development server to verify the setup
python manage.py runserver
- List all products.
- Create a new products.
- Retrieve details of a specific products.
- Update all fields of a products.
- Partially update a products (e.g., update the price).
- Delete a products.
- GET /products/: List all products.
- POST /products/: Add a new product (admin-only).
- GET /products//: Retrieve product details.
- PUT /products//: Update product (admin-only).
- DELETE /products//: Delete product (admin-only).
- GET /wishlist/: View all wishlist items for the logged-in user.
- POST /wishlist/: Add a product to the wishlist.
- DELETE /wishlist//: Remove a product from the wishlist.
- GET /reviews/<product_id>/: Get all reviews for a product.
- POST /reviews/: Add a review for a product.
- PUT /reviews//: Update a review.
- DELETE /reviews//: Delete a review.
- GET /orders/: View all orders for the logged-in user.
- POST /orders/: Place a new order.
- GET /orders//: Retrieve details of a specific order.
- PUT /orders//: Update order status (admin-only).
- POST /register/: Register a new user.
- POST /login/: Login to get a JWT token.
- GET /profile/: View the user profile.
This API uses token-based authentication to secure the endpoints. To access the API, users must obtain a token.
- Install Dependencies: Make sure
djangorestframework
anddjangorestframework-simplejwt
are installed.pip install djangorestframework pip install djangorestframework-simplejwt