Scenario 1: REST service accepting HTTP GET requests and sending responses - 6.1

Talend Components Reference Guide

Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
Data Governance
Data Quality and Preparation
Design and Development
Talend Studio

This scenario describes the process of accepting an HTTP request from the client, processing it and sending the response back.

Configuring the tRESTRequest component

  1. Drop the following components from the Palette onto the design workspace: a tRESTRequest, a tXMLMap and two tRESTResponse.

  2. Double-click tRESTRequest in the design workspace to display its Basic settings view.

  3. Fill the REST Endpoint field with the URI location where the REST-ful web service will be accessible for requests. For example, "".


    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.

  4. Click the [+] button to add one line in the REST API Mapping table.

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

  6. Click OK to save the schema.

  7. Select GET from the list in the HTTP Verb column.

  8. Fill the field in the URI Pattern column with "/{id}/".

  9. 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 "/number".

Configuring the tXMLMap component

  1. Connect tRESTRequest to tXMLMap using the Row > GetOneUser connection.

  2. Double-click tXMLMap in the design workspace to open the Map Editor.

  3. Click the [+] button on the top right to add an output and name it as ResponseUsers.

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

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

  6. Right-click on the foo node created in the previous step and select As loop element.

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

  8. Click OK to save the settings.

Configuring the tRESTResponse component

  1. Connect tXMLMap to a tRESTResponse using Row > ResponseUsers connection.

    The schema defined in tXMLMap is retrieved in tRESTResponse automatically.

  2. Select OK(200) from the Return status code list.

  3. Leave the rest of the settings as they are.

  4. Connect tRESTRequest to the other tRESTResponse using the Row > GetUserNumber connection.

Saving and executing the Job

  1. Save the Job and press F6 to execute it.

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

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