Skip to content

A Django REST API for e-commerce with JWT authentication, product management, shopping cart, orders, and payments.

Notifications You must be signed in to change notification settings

HAMED707/Ecommerce-REST-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

E-commerce REST API

A Django REST API for e-commerce with JWT authentication, product management, shopping cart, orders, and payments.

This project follows the Service Layer Pattern with clear separation:

  • API Layer (api/) - Handles HTTP requests/responses
  • Business Logic (services.py) - Core business rules
  • Data Layer (models.py) - Database models

Project Structure

backend/
├── accounts/           # User management (models, services)
├── products/           # Product catalog (models, services)
├── cart/              # Shopping cart logic
├── orders/            # Order processing
├── payments/          # Payment handling
└── api/               # API Layer (separated)
    ├── accounts_api/  # Auth endpoints
    ├── products_api/  # Product endpoints
    ├── cart_api/      # Cart endpoints
    ├── orders_api/    # Order endpoints
    └── payments_api/  # Payment endpoints

Testing with Postman

Collection: API.postman_collection.json

Import the collection into Postman and run the "Complete E2E Test Scenario" folder.

Test Flow

RegisterLoginBrowse ProductsAdd to CartView CartCreate Shipping AddressCreate OrderProcess PaymentView Order History

api-test.mp4

API Endpoints

Category Endpoint Method Auth
Auth /api/auth/register/ POST
/api/auth/login/ POST
/api/auth/refresh/ POST
/api/auth/profile/ GET/PUT
Products /api/products/ GET
/api/products/{id}/ GET
/api/products/{id}/reviews/ POST/GET ✅/❌
Cart /api/cart/ GET
/api/cart/add/ POST
/api/cart/items/{product_id}/ PUT/DELETE
Orders /api/orders/ GET
/api/orders/create/ POST
/api/orders/{id}/ GET/PUT
/api/orders/shipping-addresses/ GET/POST
Payments /api/payments/ GET
/api/payments/create/ POST
/api/payments/{id}/ GET

Installation

# Clone and navigate
git clone <repository-url>
cd RESTAPI_Project

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

Database Setup (PostgreSQL)

chmod +x setup_db.sh
./setup_db.sh

Sample Data Setup

Option 1: Load fixtures (offline data)

python manage.py loaddata products/fixtures/sample_data.json

Option 2: Fetch from fake API (online data)

python manage.py populate_products

Running

cd backend
python manage.py runserver

API: http://localhost:8000/api
Admin: http://localhost:8000/admin

About

A Django REST API for e-commerce with JWT authentication, product management, shopping cart, orders, and payments.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published