April 2018
Beginner
340 pages
7h 54m
English
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 file. Add the following content:
import requestsr = requests.get("http://127.0.0.1:5000")data = r.json()print(f"There are {data['people']} people. {data['cats']} of them have a cat, and {data['dogs']} of them have a dog")
In this example, we import the requests module and use it to send a GET request to our server using its get method.
Since our server returns JSON, we can use the json method to parse the result into a Python dictionary, ...