An implementation of small set of APIs for an e-commerce.
This project uses the following tools:
- python as runtime
- virtualenv way to run your python environment
- django as web framework
- postgres as database for the application
- psycopg2 as library to communicate to Postgres
- rest_framework as framework to build API on top of Django
The project has been tested on Mac only.
-
ensure you have
python
installed on your computer. -
clone this repository and
cd
into it. -
run
pip install -r requirements.txt
to install the correct dependencies. -
add your postgres env vars in
settings.py
. -
run
python manage.py migrate
to run migrations on database. -
run
python manage.py createsuperuser
to create a valid user. -
run
python manage.py runserver
to start the development server. -
send a POST request to
http://127.0.0.1:8000/auth/
with the valid user credentials as body, to get a valid token.
{
"username": "michelecapra",
"password": "password"
}
-
start navigating API adding
Authorization
header with valueToken your-token
. -
if you want you can create some data through admin.
The project is organized into two main apps:
ecommerce
: the core application that contains models, test and settings for the django app.ecommerce_api
: the set of apis and serializers, built using Django REST framework .
For this application and especially if you are a small team, I suggest to deploy this application on a Paas. This way you'll maximize on your dev team to focus on product development and leave most for the infra work to the Pass service.
We could use Heorku for this work. In that case, we should:
- create a new application in heroku.
- create a Procfile to tell Heroku how to start our django application and push it to our repo.
- link the application to our public repo in git and force a deploy.
- enable Automated Certification Management to force https for all connections.
- then we would be able to reach it at a specific address that you can get from the settings tab.
Alternatively we could use AWS to retain more control (and more work) over our infra. Still in that case, I would suggest to add a Dockerfile to containerize the application. Then we should use ECS on Fargate to deploy our application. I choose again Fargate instead of EC2 to minimize the devops work from the team.
Basically we should:
- push the image to the ECR registry.
- create an ECS application on Fargate that uses our image.
- then I would set the minimum set of instance that you want always active and set also the tracking policy to scale them when you have peak traffic.
- in front of all of this I would put and Elastic Load Balancer to redirect traffic to the different instances.