Consuming RESTful services
In this example, our sensor will read its configuration from a RESTful server by connecting it as a client and publishing its state on the same server. As a server, we will run a simple Flask application in a virtual Python environment. Let’s prepare the server in steps:
- Copy the
ch6/rest_client_ex/server
directory from the GitHub repository and switch to this directory. Install the Python requirements in a virtual environment:$ python --version Python 3.6.8 $ pyenv virtualenv 3.6.8 apptest $ pyenv local apptest (apptest) $ pip install -r requirements.txt
- Set the Flask application:
(apptest) $ export FLASK_APP=./rest_server.py
- Start the server. The
-h 0.0.0.0
option makes Flask serve on all network interfaces of the machine:(apptest) $ flask run -h 0.0.0.0 * Serving Flask app './rest_server.py' (lazy loading) <logs removed> * Running on http://10.8.0.2:5000/ (Press CTRL...