You are viewing the RapidMiner Hub documentation for version 10.2 - Check here for latest version
Request results
Previous: Create an endpoint
Having created an endpoint process and an endpoint, we are now in a position to request results via the endpoint URL. There are three steps:
Note that you are free to use any software that supports HTTP POST to communicate with the endpoint URL -- that's a large set of programs!
Identify the endpoint URL
In general, a Web API endpoint URL will take the following form:
http://$SA_HOST/$WEB_API_GROUP/api/v1/services/$deployment_path/$alias
where
$SA_HOST
is the host name of the scoring agent (e.g.,example.com/webapi
orexample.com:8099
)$WEB_API_GROUP
is the name of the Web API group to which the endpoint belongs$deployment_path
is the name you chose when you created the endpoint$alias
is the alias you assigned to the endpoint process, possibly the process name
In our example based on the Iris data set, the endpoint URL resolves as follows:
http://example.com/webapi/DEFAULT/api/v1/services/iris/identify
You can discover the endpoint URL for your endpoint within the Endpoints menu of RapidMiner AI Hub, by clicking on the icons under Endpoint Actions.
Format the input data as JSON
Your input data must be formatted as JSON, with two available data types: numeric and text, distinguished by the quotes (") around text values.
The scoring agent will transform the JSON format into rows and columns readable
by the endpoint process (rmhdf5table
) and provided to the first input port.
For example, a single row of input data for the process we created in connection with the Iris data set might take the following form.
{
"data": [
{
"a1": 5.1,
"a2": 3.5,
"a3": 1.4,
"a4": 0.2
}
]
}
Note that in JSON files, trailing commas are not permitted.
You can submit one row of data or multiple rows. In general, each row of input will consist of a single JSON object (in curly brackets), and the set of all rows is contained within a single JSON array (square brackets), as follows:
{ "data": [ {object1}, {object2}, {object3} ] }
POST the data to the endpoint URL
There are many ways of posting data to your endpoint URL. Try the following examples, after substituting your own input data and your own endpoint URL.
No matter what your method, the results are returned in JSON format, including both the input data and (in this example) the predictions.
{
"data": [
{
"a1": 5.1,
"a2": 3.5,
"a3": 1.4,
"a4": 0.2,
"confidence(Iris-setosa)": 1.0,
"confidence(Iris-versicolor)": 0.0,
"confidence(Iris-virginica)": 0.0,
"prediction(label)": "Iris-setosa"
}
]
}
Post data using the test page
Within the Endpoints menu of RapidMiner AI Hub, under Endpoint Actions, click on Test to get a test page for your endpoint. Insert your JSON-formatted input data and click Run Test.
Post data using curl
Note that the test page also includes the option Show curl command, pre-configured for your endpoint and your test data, in this example:
curl http://example.com/webapi/DEFAULT/api/v1/services/iris/identify \
-X POST \
-H "Content-type: application/json" \
-d "{\"data\":[{\"a1\":5.1,\"a2\":3.5,\"a3\":1.4,\"a4\":0.2}]}"
Alternatively, put your input data into a file (e.g, iris.json), and you can post it as follows -- here the generic form of the endpoint URL is given.
curl http://$SA_HOST/$WEB_API_GROUP/api/v1/services/$deployment_path/$alias \
--request POST \
--header "Content-Type: application/json" \
--data @iris.json
Post data using python
Use the requests library.
import requests
endpoint_url = 'http://example.com/webapi/DEFAULT/api/v1/services/iris/identify'
my_input_data = {"data":[{"a1":5.1,"a2":3.5,"a3":1.4,"a4":0.2}]}
r = requests.post(endpoint_url, json=my_input_data)
json_output = r.json()
print(json_output)