Make yourself a new file in the same folder as your friendslist.py file named requester.py:
import jsonimport requestsclass Requester: def __init__(self): self.url = "http://127.0.0.1:5000"
As the name implies, the Requester class will be making use of the requests module to communicate with our web service. We will also need to use the json module to read any data which is returned.
In our __init__, we just need to keep a reference to the URL at which our web service operates. Keeping it here means that, if we change it for any reason, we only have one place in this class to update.
Since our web service uses both GET and POST endpoints, we can generalize our requesting by extracting it to a method:
def request(self, ...