e-commerce gommerce enhanced with JWT authentication, SqlAlchemy, SQLite persistence and deployment scripts via Docker. It has all the ready-to-use bare minimum essentials.
Features:
Up-to-date dependencies
- API Definition - the unified API structure implemented by this server
- Simple, intuitive codebase - can be extended with ease.
Flask-restX
,Flask-jwt_extended
- Docker,
Unitary tests
Get the code
$ git clone https://github.com/Ajioz/gomerce_backend.git
$ cd gomerce_backend
Start the app in Docker
$ docker-compose up --build
The API server will start using the PORT 5000
.
Step #1 - Clone the project
$ git clone https://github.com/Ajioz/gomerce_backend.git
$ cd gomerce_backend
Step #2 - create virtual environment using python3 and activate it (keep it outside our project directory)
## Virtualenv modules installation (Unix based systems)
$ virtualenv env
$ source env/bin/activate
$
##Virtualenv modules installation (Windows based systems starting from python 3)
Create a virtual environment by running "python -m venv env"
Activate the virtual environment by running: ". env/scripts/activate"
Step #3 - Install dependencies in virtual env
$ pip install -r requirements.txt <-- ### Mac users
Install the dependencies by running "pip install -r requirements.txt" <-- ### Windows users
Step #4 - setup
flask
command for our app
$ export FLASK_APP=run.py
$ export FLASK_ENV=development
For Windows-based systems
$ (Windows CMD) set FLASK_APP=run.py
$ (Windows CMD) set FLASK_ENV=development
$
$ (Powershell) $env:FLASK_APP = ".\run.py"
$ (Powershell) $env:FLASK_ENV = "development"
Step #5 - start test APIs server at
localhost:5000
$ flask run
Use the API via POSTMAN
or Swagger Dashboard.
api-server-flask/
├── api
│ ├── config.py
│ ├── __init__.py
│ ├── models.py
│ └── routes.py
├── Dockerfile
├── README.md
├── requirements.txt
├── run.py
└── tests.py
For a fast set up, use this POSTMAN
file: attached in the root folder api.postman_collection.json
Register -
api/users/register
(POST request)
POST api/users/register
Content-Type: application/json
{
"username":"yourUsername",
"password":"yourPassword",
"email":"yourEmail"
}
Login -
api/users/login
(POST request)
POST /api/users/login
Content-Type: application/json
{
"password":"yourPassword",
"email":"yourEmail"
}
Logout -
api/users/logout
(POST request)
POST api/users/logout
Content-Type: application/json
authorization: JWT_TOKEN (returned by Login request)
{
"token":"JWT_TOKEN"
}
Run tests using pytest tests.py