The requests module
Requests was written to make HTTP requests very simple and human-readable. In simple terms, it lets us visit a web address directly in Python code instead of having to use a browser. This also gives us back the data returned from the server, meaning we can make use of it in our Python code.
We can use requests to grab data back from our flask web service and use it in some Python code. We will begin with a small demo script which will make use of the data which is being returned from our index
function.
First things first; we need to install the requests
module via pip
. Make sure your virtual environment is sourced and run pip install requests
in your command line.
Sending a GET request
A GET request allows the requester (often called a client) to receive some information from a server. We can use a GET request to ask our server for some data in JSON format, which we can then use in the rest of the script.
Ensure your flask server is still running, then, open up a new Python...