Categories

Versions

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,或者RapidMiner AI中心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 topublicin the URL.

However, in a typical web-service scenario, you won'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 isinstalled
  • RapidMiner Studio isconnectedto the remote repository.
  • 的过程ss you want to implement as a 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:

Let us create web services for both of them, taking the following steps:

  1. 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.

  2. 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.
  3. 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