To access a REST service within Python we strongly recommend the ‘requests’ module.
Reading (GET request)
import requests url = '%(schema)s://%(host)s:%(port)s/%(path)s?%(query)s' properties = { 'schema': 'http', 'host': 'localhost', 'port': '8001', 'path': 'HMI/sharp_cea_720s_nrt', 'query': 'start=2016-01-19T00:00:00Z&end=2016-01-19T00:00:00Z&meta=false' } res = requests.get(url % properties) resJson = res.json()
Writing (POST request)
import requests data = { 'data': {}, 'lat_hg': 0, 'long_carr': 0, 'long_hg': 0, 'time_start': '2016-08-26T06:29:01.424Z' } url = '%(schema)s://%(host)s:%(port)s/%(path)s' properties = { 'schema': 'http', 'host': 'localhost', 'port': '8002', 'path': 'region/myDataset' } headers = {'Content-Type': 'application/json'} res = requests.post(url % properties, headers=headers, json=data)
The properties of the URLs are according to the ones enlisted at http://localhost:8001/ui (hmi service), http://localhost:8002/ui (property service), http://localhost:8003/ui (workflow service) and http://localhost:8004/ui (prediction service).