August 17, 2023

tREST – Docs for ESB 5.x

tREST

tREST_icon32_white.png

tREST properties

Component family

Internet

 

Function

The tREST component sends HTTP
requests to a REpresentational State Transfer (REST) Web service
provider and gets responses correspondingly.

Purpose

The tREST component serves as a
REST Web service client that sends HTTP requests to a REST Web
service provider and gets the responses.

Basic settings

Schema and Edit
Schema

A schema is a row description, it defines the number of fields
that will be processed and passed on to the next component.

This component always uses a built-in, read-only schema that
contains two columns:

Body: stores the result from
the server end.

ERROR_CODE: stores the HTTP
status code from the server end when an error occurs during the
invocation process. The specific meanings of the errors codes are
subject to definitions of your Web service provider. For reference
information, visit en.wikipedia.org/wiki/List_of_HTTP_status_codes.

Click Edit Schema to view the
schema structure.

Warning

Changing the schema type may result in loss of the
schema structure and therefore failure of the
component.

 

URL

Type in the URL address of the REST Web server to be invoked.

 

HTTP Method

From this list, select an HTTP method that describes the desired
action. The specific meanings of the HTTP methods are subject to
definitions of your Web service provider. Listed below are the
generally accepted HTTP method definitions:

– GET: retrieves data from the
server end based on the given parameters.

– POST: creates and uploads data
based on the given parameters.

– PUT: updates data based on the
given parameters, or if the data does not exist, creates it.

– DELETE: removes data based on the
given parameters.

 

HTTP Headers

Type in the name-value pair(s) for HTTP headers to define the
parameters of the requested HTTP operation.

For the specific definitions of HTTP headers, consult your REST
Web service provider. For reference information, visit en.wikipedia.org/wiki/List_of_HTTP_headers.

 

HTTP Body

Type in the payload to be uploaded to the server end when the
POST or PUT action is selected.

Advanced settings

tStatCatcher Statistics

Select this check box to gather the Job processing metadata at the
Job level as well as at each component level.

Global Variables

ERROR_MESSAGE: the error message generated by the
component when an error occurs. This is an After variable and it returns a string. This
variable functions only if the Die on error check box is
cleared, if the component has this check box.

A Flow variable functions during the execution of a component while an After variable
functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl +
Space
to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio
User Guide.

Usage

Use this component as a REST Web service client to communicate
with a REST Web service provider. It must be linked to an output
component.

Log4j

The activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User
Guide
.

For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html.

Limitation

JRE 1.6 must be running for this component to work
properly.

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

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

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

Use_Case_tREST02.png
  • 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.

Note

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.

Use_Case_tREST03.png
  • 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.

Use_Case_tREST04.png

Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x