This repo provides a simple Python-Flask Server with several RESTful APIs for learning and testing. I created it to learn about running containers within Pods in Kubernetes, but could be used to test across many orchestrated environments. Deployed on a virtual machine, or baremetal, it could be a useful tool demonstrating HTTP connectivity.
The current release of this code is also available as a containerized image on https://hub.docker.io/.
Alternatively, this code can easily be transformed into a docker image following the steps included in this repo. Steps on deploying code found in this repository can be found at the bottom of the README file.
HTTP/1.1 200 OK
$HTTP_HEADERZ
{
"env": # dump of available environmental variables,
"version": $VERSION
}
HTTP/1.1 200 OK
$HEADER_FIELDS
{
"delay in seconds": $HEALTH_DELAY,
"version": $VERSION,
"healthy": true
}
HTTP/1.1 200 OK
$HTTP_HEADERZ
{
"from": "$REMOTE_IP",
"host": ""$HOST:$PORT"",
"version": "$VERSION"
}
HTTP/1.1 200 OK
$HTTP_HEADERZ
{
"thanks": "Thank You for training with Alta3 Research!",
"alta3":
{
"homepage": "https://alta3.com",
"posters": "https://alta3.com/posters",
"youtube": "https://www.youtube.com/user/Alta3Research/videos"
},
"version": "$VERSION"
}
Returns a 200 containing a "SQUAKK!!" + the [ANYTHING] string sent to the API endpoint.
HTTP/1.1 200 OK
$HTTP_HEADERZ
{
"you": "Polly want a cracker?",
"parrot": "SQUAWK!! Polly want a cracker?",
"version": "I am talking parrot version $VERSION"
}
By setting the following environment variables, you can change the runtime behaviour of simpleservice:
- PORT0 - the port simpleservice is serving on
- VERSION - the value of version returned in the JSON response of the /endpoint0 endpoint
- HEALTH_DELAY - delay in milliseconds that the /health endpoint responds
-
First,
git clone
the repository to your local machine.git clone https://github.com/rzfeeser/simpleflaskservice
-
Ensure Python 3.6+ has been installed on Debian / Ubuntu Machines
sudo apt install python3-pip
-
Ensure Python 3.6+ has been installed, then use
pip
to install Flask.python3 -m pip install flask
-
Run the code with Python 3.6+
python3 simpleflaskservice.py
-
Set the environmental variable
VERSION
to "24601" andPORT0
to "8887", then launch the server.VERSION=24601 PORT0=8887 python3 simpleflaskservice.py
-
First build an image.
sudo docker build -t simpleservice -f Dockerfile .
-
Launch the image in docker with the port
9010
pointing to9876
, and without hogging up the screen (-d).docker run -d -p 9010:9876 simpleflaskservice
-
OR Launch the image in docker with a random port pointing to the exposed ports.
docker run -P simpleflaskservice