One Star

[resolved] How to pass the REST Endpoint to tRestClient as a parameter

I have deployed a REST service (say, service A) job that takes an id as a parameter and returns a json object. Now I am trying to consume this service within another service (say, service B) using tRESTClient. How do I set the URL value of the tRESTClient component so that it takes the request parameter from service A? 
1 ACCEPTED SOLUTION

Accepted Solutions
Community Manager

Re: [resolved] How to pass the REST Endpoint to tRestClient as a parameter

Hi Lurdas
Design your job like this:
tRestRequest--main--tFlowToIterate--iterate--tRestClient....

To pass a input parameter to webservcice, you have to define it on tRestRequest, to do:
1. Set the Default properties of the id column as query on the schema of tRestRequest.


2. Then, you are able to get this parameter on any other component later with this expression:
(Integer)globalMap.get("row1.id")

//row1 is the flow name from tRestRequent, it is getPatient in your case, change it to (Integer)globalMap.get("getPatient.id").

3. Set the url of tRestCient as:
"http://localhost:8040/services/id/"+(Integer)globalMap.get("getPatient.id")

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
7 REPLIES
Community Manager

Re: [resolved] How to pass the REST Endpoint to tRestClient as a parameter

Hi
What's data type of input request? Document or others? If Document, you need to use a tXMLMap to build the payload and pass it to tRestClient.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] How to pass the REST Endpoint to tRestClient as a parameter

                                                                           
Thanks for the reply!! Service A is deployed in the server and it produces a json object. Service B calls service A via URL.  Since Service A requires/accepts a parameter value, if I pass the complete URL (including the parameter) to the component of tRESTClient URL, I get the json object that I can process further in Service B using the tXMLMap. I need a way to pass the parameter value that Service A needs by constructing the URL for the tRESTClient instead of hardcoding the parameter value in the URL field of the client component. Is that possible? See the image Above. How do I pass the ID 1234566 that you see in the image in the URL (i.e., ) as opposed to hardcoding it in the URL ( i.e., )?
      
Community Manager

Re: [resolved] How to pass the REST Endpoint to tRestClient as a parameter

Hi
Yes, it is possible. You can set a dynamic URL with context variable, for example:
"http://localhost:8040/services/id/"+context.id

Set a default value to context.id, and the value of context.id can be changed at run time.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] How to pass the REST Endpoint to tRestClient as a parameter

Thanks Shong!! The use of context worked. However, if I want to pass the id of the URL from another request. How do I do it? I tried to use the globalMap.get("xxx") function, but tRESTClient doesn't seem to like it. See the attached picture below.
One Star

Re: [resolved] How to pass the REST Endpoint to tRestClient as a parameter

All
I am actually working on the exact same issue right at this moment (even though it is Christmas Eve :-) ). Anyway I have been trying to use globalMap.get and have been receiving error's. Will now move on to try using a context variable. Would like to know if I should be able to get it to work with globalMap.get
Regards,
Derek O'Connor
(Hipercept1)
Community Manager

Re: [resolved] How to pass the REST Endpoint to tRestClient as a parameter

Hi Lurdas
Design your job like this:
tRestRequest--main--tFlowToIterate--iterate--tRestClient....

To pass a input parameter to webservcice, you have to define it on tRestRequest, to do:
1. Set the Default properties of the id column as query on the schema of tRestRequest.


2. Then, you are able to get this parameter on any other component later with this expression:
(Integer)globalMap.get("row1.id")

//row1 is the flow name from tRestRequent, it is getPatient in your case, change it to (Integer)globalMap.get("getPatient.id").

3. Set the url of tRestCient as:
"http://localhost:8040/services/id/"+(Integer)globalMap.get("getPatient.id")

Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] How to pass the REST Endpoint to tRestClient as a parameter

Fantastic!!! Thanks Shong!! Just one issue that I encountered with your stated design. I was not able to use Row Iterator (tFlowToIterate--iterate--tRestClient). It did not allow me. Instead, I ended up using "On Component Ok" Trigger.