function integer transform() {
string text = getRequestParameter("text");
string upperText = upperCase(text);
setResponseBody(upperText);
return ALL;
}
53. Example
In this example, we will demonstrate how to create a Data Service that returns the message converted to upper case.
The web service will be available on http://www.example.com/clover/data-service/message
Solution
Creating Data Service
Create a new Data Service REST Job.
Right click the data-service directory in the project. message
and click Finish.
Remove other components except Input and Output.
Insert the GetJobInput component: Press Shift+Space and choose the component.
Connect GetJobInput and Output with an edge.
Assign metadata to the edge.
The metadata should contain one string
field.
In GetJobInput, update the transformation to contain the following mapping:
In Output set Format to custom.
Publishing the Web Service
To publish the web service, switch to Endpoint Configuration. Set Endpoint URL.
Check request methods GET
and POST
.
Click Publish.
Verifying Functionality
To check that the service works, query the Data Service, e.g.
with wget
(or curl
). You can also use HTTPConnector.
wget --user clover --password clover "http://example.org/clover/data-service/message?text=Hello" -O file.txt
The Data Service will return HELLO
.
See the content of file.txt
file.