Categories

Versions

Request results

Previous:Create an endpoint

Having created anendpoint processand anendpoint, we are now in a position to request results via the endpoint URL. There are three steps:

  1. Identify the endpoint URL
  2. Format the input data as JSON
  3. POST the data to the endpoint URL

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_HOSTis the host name of the scoring agent (e.g.,example.com/webapiorexample.com:8099)
  • $WEB_API_GROUPis the name of the Web API group to which the endpoint belongs
  • $deployment_pathis the name you chose when you created the endpoint
  • $aliasis the alias you assigned to the endpoint process, possibly the process name

Inour examplebased 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 theEndpointsmenu of RapidMiner AI Hub, by clicking on the icons underEndpoint 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 theprocess we createdin 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 theEndpointsmenu of RapidMiner AI Hub, underEndpoint Actions, click onTest得到一个测试页面为您的端点。Insert your JSON-formatted input data and clickRun Test.

Post data using curl

Note that the test page also includes the optionShow 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 theendpoint URLis 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 therequestslibrary.

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)