Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to call REST web service and get response in talend

I have REST web Service URL- http://XYZ:8080/WebApp/search/service
If I send following json format data using Advanced Rest Client(Chrome-extension) then I get O/p as below-
Input- 
            {
    "query": {
        "text": "i lOVE inDIA",
        "service":
    }
}

Output-
            {
        -response: {
-pos:
-0:  {
text: "lOVE"
type: "JJ"
pos: "ADJECTIVE"
}
-1:  {
text: "inDIA"
type: "NN"
pos: "NOUN"
}
-2:  {
text: "lOVE inDIA"
type: ""
pos: "NOUN"
}
}
}

I tried with tRestClient but not get succeeded.
How to implement it in Talend5.6.1
Labels (4)
14 Replies
Anonymous
Not applicable
Author

I too, never got tRestClient to work for a RESTful call. However, I can successfully perform a REST call with the tREST component. I set the URL up as a context value and ensure that my input is in the appropriate JSON structure. Make sure to specify the HTTP Header of "Content-Type" to the value of "application/json". 
If you manage to get the tRestClient component working, please let me know as I'd much prefer to use that instead.
Anonymous
Not applicable
Author

With the tRESTClient component, you need to specify the Content Type and Accept Type correctly and also supply the JSON to the "string" input column and not the "body" input. That is the mistake that I have seen most when trying to get it to work with JSON
Anonymous
Not applicable
Author

For output as JSON, set the Accept Type as "any". For some reason setting it to JSON converts it to XML. Not sure why, but I just remembered this.
Anonymous
Not applicable
Author

Hi  rhall_2.0,
How to supply JSON as a String input?
Anonymous
Not applicable
Author

The tRESTClient component has an input schema with two columns; body and string. You need to supply the JSON to the string column and not the body column.
Anonymous
Not applicable
Author

Hi rhall_2.0,
                 Thanks for reply, I am just no understanding how to give json input to String column.
Please find attached screenshot.
0683p000009MAse.png
Anonymous
Not applicable
Author

If you have your JSON already formatted, just create a tFixedFlowInput component and connect it to the tRESTClient component. It will ask  "Do you want to get the schema of the target component?". Click OK. Then populate the "string" column in the tFixedFlowInput component with your JSON. Either as a String surrounded with quotes or using a context variable.
This is a basic way of doing it. All you have to do is make sure that the component that feeds the tRESTClient component has a schema of "body" and "string", and the JSON code must be passed to the "string" column.
Anonymous
Not applicable
Author

Thanks for helping,
Yes I have formatted JSON but then also I am not able to recognize how to implement it.
I have connected  tFixedFlowInput to  tRESTClient, but where to give JSON data?
should I use tFileInputJson Component for that?
Please find screenshot & Suggest me.
0683p000009MArS.png
0683p000009MArS.png
Anonymous
Not applicable
Author

There should be two columns in the tFixedFlowInput component if you connected it as I described. You only have the "string" column. Delete it and add it again and then click "OK" when the  "Do you want to get the schema of the target component?" message appears.
The next bit is a little harder. You actually put the JSON code where it needs to be, but it must be formatted as a Java string. If you wanted to send ....

Hello, my name is Richard 
....as a Java String in this column, you would send it as follows.....
"Hello, my name is Richard"

It must be enclosed in quotes. However, your JSON string has quotes in it. So these need to be escaped. To escape a quote in Java you put a \ before the quote. So, the following JSON string .....

          {
    "query": {
        "text": "i lOVE inDIA",
        "service":
    }
}
..... would be represented as....

          "{ \"query\": { \"text\": \"i lOVE inDIA\",\"service\": }}"
Ideally, you would let Talend build your JSON and then you would not need to worry about this.