An E-commerce APIs built using Django Rest Framework
- Basic e-commerce features
- User profile and registration
- JWT based authentication
- Custom permissions set for necessary endpoints
- Payment integration using Stripe
- Customized Admin Panel
- Redis caching
- Tested API endpoints using pytest
- Error tracking with Sentry
- Performed performance test [local machine gunicorn web server]
- Logged essential external service call
- Documentation using DRF spectacular
- Dockerized for local development and production
Technology | Purpose |
---|---|
Django Rest Framework | APIs Building |
Poetry | Dependency Management |
PostgreSQL | Database |
Celery | Background Task |
Redis | Caching |
Pytest | API Testing |
Locust | Performance Testing |
Djoser | User Registration |
Simple-JWT | User Authentication |
Stripe | Payment |
DRF spectacular | Documentation |
Error Tracking | Sentry |
Docker | Containerization |
-
Clone the project
https://github.com/chapainaashish/shopapi
-
Install poetry in your system
curl -sSL https://install.python-poetry.org | python3 -
-
Install the dependencies
poetry install
-
Enter into the virtual environment
poetry shell
-
Rename the
.env_example
to.env
and update the environment variables accordingly -
Set
DJANGO_SETTINGS_MODULE
according to your need- For development:
DJANGO_SETTINGS_MODULE = 'shopapi.settings.development'
- For production :
DJANGO_SETTINGS_MODULE = 'shopapi.settings.production'
- Set database
HOST
USER
PASSWORD
PORT
in.env
file for production
- Set database
- For development:
-
Install sentry-sdk
pip install --upgrade 'sentry-sdk[django]'
-
Install docker in your system
https://docs.docker.com/desktop/
-
Run redis using docker
docker run -d -p 6379:6379 redis
-
Start the celery worker
celery -A shopapi worker --loglevel=info
-
Install the stripe cli tool on your system
https://stripe.com/docs/stripe-cli#install
-
Configure the webhook
stripe listen --forward-to localhost:8000/store/webhooks/stripe/
-
Create the migration
python manage.py migrate
-
Create the superuser
python manage.py createsuperuser
-
Run the development server
python manage.py runserver
-
Head over to
http://localhost:8000/admin
on your browser -
Run the test using command
pytest
orpwt
for continuous testing [Optional] -
Generate test coverage in html using
pytest --cov --cov-report=html
[Optional] -
Run celery flower to manage celery workers
celery flower
[Optional] -
Run the performance test using
locust -f locustfiles/browse_product.py
[Optional] -
Read the API documentation on
http://127.0.0.1:8000/api/schema/swagger-ui/
[Optional]
-
Clone the project
https://github.com/chapainaashish/shopapi
-
Rename the
.env_example
to.env
and update the environment variables accordingly -
Set
DJANGO_SETTINGS_MODULE
according to your need- For development:
DJANGO_SETTINGS_MODULE = 'shopapi.settings.development'
- For production :
DJANGO_SETTINGS_MODULE = 'shopapi.settings.production'
- Set database
HOST
USER
PASSWORD
PORT
in.env
file for production
- Set database
- For development:
-
Install docker in your system
https://docs.docker.com/desktop/
-
Rename
docker-compose-dev.yml
todocker-compose.yml
for development [Skip for production] -
Build docker image and run
$ docker-compose up
$ docker-compose exec web python manage.py createsuperuser
- Head over to
http://localhost:8000/admin
on your browser
Endpoints | User | ||
---|---|---|---|
Anonymous | Authenticated+Authorized | Admin | |
collection | |||
store/collection | GET | GET | GET, POST |
store/collection/pk | GET | GET | GET, PUT, PATCH, DELETE |
product | |||
store/product | GET | GET | GET, POST |
store/product/pk | GET | GET | GET, PUT, PATCH, DELETE |
store/product/pk/reviews | GET | GET, POST | GET, POST |
store/product/pk/reviews/pk | GET | GET, PATCH, DELETE | GET, PATCH, DELETE |
cart | |||
store/cart | - | GET, POST | GET, POST |
store/cart/pk | - | GET | GET |
store/cart/pk/items | - | GET, POST | GET, POST |
store/cart/pk/items/pk | - | GET, PATCH, DELETE | GET, PATCH, DELETE |
order | |||
store/order | - | GET, POST | GET, POST |
store/order/pk | - | GET | GET, PATCH, DELETE |
store/order/pk/items | - | GET | GET |
store/order/pk/items/pk | - | GET | GET, DELETE |
payment | |||
store/payment | - | GET | GET |
store/payment/pk | - | GET | GET, PATCH, DELETE |
stripe/payment/pk | - | POST | POST |
user | |||
user/address | - | GET, POST | GET, POST |
user/address/pk | - | GET, PUT, PATCH, DELETE | GET, PUT, PATCH, DELETE |
user/profile | - | GET, POST | GET, POST |
user/profile/pk | - | GET, PATCH, DELETE | GET, PATCH, DELETE |
- https://docs.djangoproject.com/en/4.1/
- https://www.django-rest-framework.org/
- https://python-poetry.org/docs/
- https://docs.celeryq.dev/en/stable/getting-started/introduction.html
- https://pytest-django.readthedocs.io/en/latest/tutorial.html
- https://django-debug-toolbar.readthedocs.io/en/latest/installation.html
- https://djoser.readthedocs.io/en/latest/getting_started.html
- https://stripe.com/docs/stripe-cli
- https://docs.docker.com/engine/install/
- https://drf-spectacular.readthedocs.io/en/latest/