This scenario describes the process of accepting an HTTP request from the client, processing it and sending the response back.
Drop the following components from the Palette onto the design workspace: a tRESTRequest, a tXMLMap and two tRESTResponse.
Double-click tRESTRequest in the design workspace to display its Basic settings view.
Fill the REST Endpoint field with the URI location where the REST-ful web service will be accessible for requests. For example, "http://192.168.0.235:8088/user".
If you want your service to be available on both HTTP and HTTPS, fill the field with a relative path. For example, if you type in "/test", your service will be available on both http://<DefaultHTTPEnpointAddress>/test and https://<DefaultHTTPSEnpointAddress>/test, provided that you have configured your Runtime container to support HTTPS. For more information, see the Talend ESB Container Administration Guide.
Click the [+] button to add one line in the REST API Mapping table.
Select the newly-added line and click the [...] button in the Output Flow column to add a schema for the output flow.
In this scenario, the output flow will be named as GetOneUser.
Then click the [+] button to add a new line id to the schema in the dialog box.
Click OK to save the schema.
Select GET from the list in the HTTP Verb column.
Fill the field in the URI Pattern column with
In the same way, add another line in the REST API Mapping table and name this schema GetUserNumber. Add a line string of String type to the schema. Enter query in the Comment field to get the number parameter in the request.
Select GET from the list in the HTTP Verb column. Fill the field in the URI Pattern column with
Connect tRESTRequest to tXMLMap using the Row > GetOneUser connection.
Double-click tXMLMap in the design workspace to open the Map Editor.
Click the [+] button on the top right to add an output and name it as ResponseUsers.
Click the [+] button on the bottom right to add two columns for the output.
Name the first column as body and set the Type to Document.
Name the second column as string and set the Type to String.
Right-click on the node root and select Create Sub-Element to create a sub-element. Name the sub-element as foo in the popup dialog box.
Right-click on the foo node created in the previous step and select As loop element.
Select the id column of the GetOneUser table to the left and drop it onto the Expression field of the foo node of the ResponseUsers table to the right.
Click OK to save the settings.
Connect tXMLMap to a tRESTResponse using Row > ResponseUsers connection.
The schema defined in tXMLMap is retrieved in tRESTResponse automatically.
Select OK(200) from the Return status code list.
Leave the rest of the settings as they are.
Connect tRESTRequest to the other tRESTResponse using the Row > GetUserNumber connection.
Save the Job and press F6 to execute it.
Go to your browser if you want to test the service.
The HTTP request for a user id is accepted by the REST service and the HTTP response is sent back to the server.
Repeat this step and type in http://localhost:8088/user/number?string=123 in the address bar. Press Enter.
An XML parsing error is reported because the returned body content is String type. Right-click the browser an select View Page Source in the context menu.
You can see that 123 is returned in the response.