https://github.com/sartim/flask_shop_api
REST API for an online shop developed using flask framework which runs as a websocket server using socketio.
https://github.com/sartim/flask_shop_api
flask python3 rest-api socketio-server
Last synced: 10 months ago
JSON representation
REST API for an online shop developed using flask framework which runs as a websocket server using socketio.
- Host: GitHub
- URL: https://github.com/sartim/flask_shop_api
- Owner: sartim
- Created: 2019-03-19T12:28:44.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-03T19:33:20.000Z (about 2 years ago)
- Last Synced: 2025-04-07T17:41:59.431Z (about 1 year ago)
- Topics: flask, python3, rest-api, socketio-server
- Language: Python
- Homepage: https://flask-shop-api.vercel.app
- Size: 971 KB
- Stars: 2
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flask Shop API
[](https://github.com/sartim/flask_shop_api)

REST API which exposes endpoints both for an online shop and a CMS admin. It's developed using flask framework which runs as a socketio server.
##Features
* RBAC
* API Caching (Redis)
* Fulltext search (Elasticsearch)
## Setup
**Requirements**
* Python 3+
* Virtualenv
* Heroku CLI
**Create virtual environment & install requirements**
$ virtualenv -p python3
$ source /bin/activate
$ pip install -r requirements.txt
**Make migrations**
$ python manage.py db init
$ python manage.py db migrate
$ python manage.py db upgrade
**Add dotenv to project root**
You should create a .env file on the project root using the following format:
When using PostgreSQL DB_URL
DEV=TRUE
TEST=FALSE
PROD=FALSE
DATABASE_URL={DB_URL}
SECRET_KEY={SECRET}
PAGINATE_BY=20
ADMIN_EMAIL={EMAIL}
APP_EMAIL={EMAIL}
APP_EMAIL_PASSWORD={PASSWORD}
LOG_LEVEL=DEBUG
When using sqlite for test
DEV=FALSE
TEST=TRUE
PROD=FALSE
SECRET_KEY=my_precious
PAGINATE_BY=20
ADMIN_EMAIL=admin@mail.com
APP_EMAIL=app@email.com
APP_EMAIL_PASSWORD=letmein
LOG_LEVEL=DEBUG
**Running app using manage.py**
$ python manage.py run
**Running app using gunicorn**
$ gunicorn --worker-class eventlet -w 1 -b 0.0.0.0:8000 --timeout 300 wsgi:app
**Building & running on docker**
$ docker build --build-arg ENV=PROD --build-arg PAGINATE_BY=20 --build-arg CACHED_QUERY=CACHED_QUERY --build-arg REDIS_EXPIRE=3600 --build-arg SECRET_KEY=my_secret --build-arg REDIS_URL=redis://host:port --build-arg DATABASE_URL=postgresql://username:password@hostname:5432/database --build-arg ADMIN_EMAIL=test@mail.com --build-arg APP_EMAIL=test@email.com --build-arg APP_EMAIL_PASSWORD=password --build-arg LOG_LEVEL=ERROR -t flask-shop-api:latest .
$ docker run -p 8000:8000 flask-shop-api
**Building & running on k8**
$ docker build --build-arg ENV=PROD --build-arg PAGINATE_BY=20 --build-arg CACHED_QUERY=CACHED_QUERY --build-arg REDIS_EXPIRE=3600 --build-arg SECRET_KEY=my_secret --build-arg REDIS_URL=redis://host:port --build-arg DATABASE_URL=postgresql://username:password@hostname:5432/database --build-arg ADMIN_EMAIL=test@mail.com --build-arg APP_EMAIL=test@email.com --build-arg APP_EMAIL_PASSWORD=password --build-arg LOG_LEVEL=ERROR -t flask-shop-api:latest .
$ eval $(minikube docker-env)
$ kubectl apply -f k8deploy.yaml
$ kubectl expose deployment flask-shop-api-deploy --type=NodePort --port=8000
$ minikube service flask-shop-api-deploy
Optional forwarding port
$ kubectl port-forward service/flask-shop-api-deploy 5001:8000
**Running unittests**
First setup the .env for test environment then run the following command from project root:
$ pytest
**Other Commands on**
python manage.py --help
_(Optional)Install Ipython to get interactive shell using Ipython for the app_
**Demo URL**
`https://flask-shop-api.vercel.app`
###### Login Credentials
username: `demo@mail.com`
password: `demo_pass`
###### Routes
* /api/v1/auth/generate-jwt
* /api/v1/users
* /api/v1/categories
* /api/v1/products
* /api/v1/statuses
* /api/v1/orders
* /api/v1/reviews