You are viewing the RapidMiner Server documentation for version 9.7 -Check here for latest version
Create a web service
What is a web service?
See also thevideo introductionto web services.
In the context of RapidMiner, aweb serviceis aprocessthat can be called by means of a URL. The URL is a link to RapidMiner AI Hub, similar to the following:
http://RMServerHost:8080/api/rest/process/YourServiceName?customerID=3
The URL can take a query parameter as input, in this examplecustomerID=3
, and it delivers a result in a format of your choice, including the following:
- JSON
- XML
- HTML
- OData
- and others...
To see the results, either you must authenticate yourself as a registereduser, or RapidMiner AI Hub must be configured to accept queries byanonymous users. The URL for a web service available to anonymous users will take the following slightly different form:
http://RMServerHost:8080/api/rest/public/process/YourServiceName?customerID=3
Notice the reference topublic
in the URL.
然而,在一个典型的web服务场景中,你我n't call this URL yourself. You will build an app to serve some useful purpose, and the app will call the URL, authenticating itself via atoken. Web services can easily be embedded into web pages and other applications. They make it possible to serve the results of a RapidMiner process over HTTP.
Before you begin
Before creating a web service, make sure that:
- RapidMiner AI Hub isinstalledandconfigured.
- RapidMiner Studio isconnectedto the remote repository.
- 你希望实现为web的过程service is saved in theremote repository.
- Your process is designed so that the data you need is delivered to the first result ("res") port. A web service returns data only from the first port.
If you don't yet have a process to implement as a web service, or you are unsure how to build such a process, you may find it helpful to work through an example. InPredictive Maintenance, we explicitly build two processes that, in the remainder of this document, are implemented as web services.
Step by step
See also thevideo introductionto creating a web service, including a discussion of theanonymous userand of some security precautions you need to take when providing public access to RapidMiner AI Hub.
At theconclusion of Predictive Maintenance, we saved two new processes to a RapidMiner AI Hub repository:
- Predictive_Maintenance_web_service_without_parameters, to predict the probability of failure for all values of "Machine ID". This process has no macro, and the URL will not include a query parameter.
- Predictive_Maintenance_web_service_with_parameters, to predict the probability of failure for a particular value of "Machine ID". This process contains amacro, and when the web service is created, the URL will include a query parameter corresponding to a particular value of "Machine ID".
Let us create web services for both of them, taking the following steps:
Create a web service. Select one of the following entry points:
- In RapidMiner Studio, in the remote repository, right-click on the process and chooseBrowseto open the Repository Browser on RapidMiner AI Hub. ClickExport as Web Service.
- On RapidMiner AI Hub, chooseRepository>Browse Repository, navigate to the process of interest, select it, and clickExport as Web Service.
- On RapidMiner AI Hub, chooseProcesses>Web Services, and click onCreate new web service.
Of these, the first is perhaps the best, because it takes you directly to the process of interest.
The screenshot below shows theEdit Web Servicedialog for the second process,Predictive_Maintenance_web_service_with_parameters. Notice that RapidMiner AI Hub automatically detects the macro in this process, and assigns aURL query parameterwith the same name. You can if you like change the query parameter. You can also change theService ID; it need not be the same as the process name. However, theData sourcemust accurately locate the process on RapidMiner AI Hub, and the macro name must be the same as the one that was written in that process. If you look at the drop-list for theOutput format, you will see that there are numerous options. In this example, we have chosen "JSON"; RapidMiner AI Hub sets the MIME-type accordingly.
Edit web service. Make sure to fill in the following fields:
- Service ID: the name of the web service, as it will appear in the URL. It need not be the same as the process name.
- Data source: the location of the process on RapidMiner AI Hub
- Output format: the output format. Choices include JSON, XML, HTML, OData, and others.
- Parameter binding: The URL query parameter, if it exists, need not be the same as the macro name.
ClickSubmitto save the process as a web service.
The page that opens next (Processes>Web Services) lists available web services by their ID. Here you have the opportunity to test the the web service and to edit the web service, if necessary. You can also delete it.
With parameters
When you test the servicePredictive_Maintenance_web_service_with_parameters, with JSON output, the result is the following. To test the functioning of theURL query parameter, you can change the value and clickTest.
Once the web service is ready, you can call it from the browser via theDirect Linklisted on the right side of the page, or you can embed the result in an
With RapidMiner AI Hub running locally on a laptop, the URL takes the following form:
http://localhost:8080/api/rest/process/Predictive_Maintenance_web_service_with_parameters?machineID=M_0221
In general,localhost
will be replaced by your RapidMiner AI Hub hostname. Suppose that when creating the web service we had given a simpler name, such as "needs-repair", to the web service ID. Then the URL would have been simpler:
http://localhost:8080/api/rest/process/needs-repair?machineID=M_0221
but in either case, with JSON output, the result is the same:
{ "Machine_ID":"M_0221", "confidence(no)":0.10256410256410256, "confidence(yes)":0.8974358974358979, "prediction(Failure)":"yes" }
Without parameters
When you test the servicePredictive_Maintenance_web_service_without_parameters, with Table output, the result is the following:
Again, once the web service is ready, you can call it from the browser via theDirect Linklisted on the right side of the page, or you can embed the result in an
With RapidMiner AI Hub running locally on a laptop, the URL takes the following form:
http://localhost:8080/api/rest/process/Predictive_Maintenance_web_service_without_parameters
and the browser displays the result as a table: