Skip to main content

Creating and retrieving data by invoking REST Web service

This scenario describes a simple Job that invokes a REST Web service to create a new customer record on the server end and then retrieve the customer information. When executed, the Job displays relevant information on the Run console.

For more technologies supported by Talend, see Talend components.

  • Drop the following components from the Palette onto the design workspace: two tREST components and two tLogRow components, and label the two tREST components to best describe the actions to perform.

  • Connect each tREST to one tLogRow using a Row > Main connection.

  • Connect the first tREST to the second tREST using a Trigger > OnSubjobOK connection.

  • Double-click the first tREST component to open its Basic settings view.

  • Fill the URL field with the URL of the Web service you are going to invoke. Note that the URL provided in this use case is for demonstration purposes only and is not a live address.

  • From the HTTP Method list, select POST to send an HTTP request for creating a new record.

  • Click the plus button to add a line in the HTTP Headers table, and type in the appropriate name-value key pair, which is subject to definition of your service provider, to indicate the media type of the payload to send to the server end. In this use case, type in Content-Type and application/xml. For reference information about Internet media types, visit www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.

  • Fill the HTTP Body field with the payload to be uploaded to the server end. In this use case, type in <Customer><name>Steven</name></Customer> to create a record for a new customer named Steven.

Information noteNote:

If you want to include double quotation marks in your payload, be sure to use a backslash escape character before each of the quotation marks. In this use case, for example, type in <Customer><name>\"Steven\"</name></Customer> if you want to enclose the name Steven in a pair of double quotation marks.

  • Double-click the second tREST component to open its Basic settings view.

  • Fill the URL field with the same URL.

  • From the HTTP Method list, select GET to send an HTTP request for retrieving the existing records.

  • In the Basic settings view of each tLogRow, select the Print component unique name in front of each output row and Print schema column name in front of each value check boxes for better identification of the output flows.

  • Save your Job and press F6 to launch it.

    The console shows that the first tREST component sends an HTTP request to the server end to create a new customer named Steven, and the second tREST component successfully reads data from the server end, which includes the information of the new customer you just created.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!