Creating the Client Application to Use the Model
Once the REST API is up and running, and it has been tested to be working correctly, you can build the client side of things. Since this book revolves around Python, it is fitting to build the client using Python. Obviously, in real life, you would most likely build your clients for the iOS, Android, macOS, and Windows platforms.
Our Python client is pretty straightforward—formulate the JSON string to send to the service, get the result back in JSON, and then retrieve the details of the result:
import json
import requests
def predict_diabetes(BMI, Age, Glucose):
url = 'http://127.0.0.1:5000/diabetes/v1/predict'
data = {"BMI":BMI, "Age":Age, "Glucose":Glucose}
data_json = json.dumps(data)
headers = {'Content-type':'application/json'}
response = requests.post(url, data=data_json, headers=headers)
result = json.loads(response.text)
return result...