A template for a bare minimum Flask API - no database backend. An endpoint 'sums' is added as an example:
https://en.wikipedia.org/wiki/Summation
Unit Tests use the unittest library.
If using a Python IDE (Visual Studio Code, PyCharm, etc) it will try to detect the Python interpreter. The instructions below can be applied directly from the command line, without an IDE.
Note: this project was tested with Python >= 3.10.
You must have Docker locally installed. And also, install the following system dependencies:
Mac OS:
# source system-macos-dependencies.sh
Ubuntu 20.04 (Jammy):
# source system-ubuntu20-dependencies.sh
CentOS 7:
# source system-centos7-dependencies.sh
Note: this project has been extensively tested only with Ubuntu 20.04.
Run the commands:
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install -r requirements.txt
N/A
$ export CONFIGENV=api.config.TestingConfig; coverage run -m unittest discover
$ coverage report -m --omit=".venv/*,tests/*"
$ coverage html --omit=".venv/*,tests/*"
$ pylint api/*.py tests/*.py
In your IDE or terminal:
$ export CONFIGENV=api.config.TestingConfig; python -m api.app
RestFUL API endpoints:
or using Docker:
# docker build --tag api:develop .
# docker run --rm -it --name api -p 8080:8080 -e CONFIGENV=api.config.TestingConfig api:develop
RestFUL API endpoints:
# docker build --tag api:latest .
# docker run --rm -it --name api -p 8080:8080 -e CONFIGENV=api.config.ProdConfig api:latest
RestFUL API endpoints: