Webservice that returns db table in Json - How?

One Star

Webservice that returns db table in Json - How?

I'm new to Talend ESB and there are no good tutorials or examples I have found to build a route or a job that represents a REST endpoint that reads a database query and returns the results as a json payload while being able to branch based on input parameters.
Here is what I am trying to do
url:  host/getData?action=view1  - return json payload from view 1
      host/getData?action=view2  - return json payload from view 2
tRestRequest --> tFlowToIterate --> tOracleInput --> tXMLMap  --> tRestResponse 
While this seems to work, for both XML / JSON - I don't see how to split the job into multiple routes to pull from different views if I have different parameters.
So, I tried to do this with a route that calls a job
chttp --> cMessageRouter -->  job1 --> routeInput --> tFlowToIterate --> tOracleInput --> tWriteJsonFields --> tRouteOutput
                                    |--> job2 --> routeInput --> tFlowToIterate --> tOracleInput --> tWriteJsonFields --> tRouteOutput
The message router in this case makes it easy to branch routes on the input parameters, but now the job returns only the last row of the database instead of all the rows?
My simple question is what components should I use to do this?  It should be straight forward I believe, but it is not documented well anywhere that is easy to find.  Maybe this post will help me and others who might be looking for these answers.
Employee

Re: Webservice that returns db table in Json - How?

Hi Bret,
There are a variety of ways to accomplish this.  Since your different views are essentially different flows, I would build them each as different REST API mappings if you're able to change your URI to use the path rather than query parameters for the views.
host/views/view1
host/views/view2
If you must send the action as a query parameter then you could take a look at the expression filter in the tMap/tXmlMap component.  This would allow you to conditionally join/query to your different databases and produce different outputs to different tRestResponse components.  The expression filter is available by clicking the button that has a white arrow with a green "+" sign on it.
One Star

Re: Webservice that returns db table in Json - How?

Hi Bret,
There are a variety of ways to accomplish this.  Since your different views are essentially different flows, I would build them each as different REST API mappings if you're able to change your URI to use the path rather than query parameters for the views.
host/views/view1
host/views/view2
If you must send the action as a query parameter then you could take a look at the expression filter in the tMap/tXmlMap component.  This would allow you to conditionally join/query to your different databases and produce different outputs to different tRestResponse components.  The expression filter is available by clicking the button that has a white arrow with a green "+" sign on it.

Thanks for the response.  How would I do this in the flow?  I have this iterate component in front of the database.  Do I need this?  Not sure how to determine which components can talk to each other (other than drawing rows to try to connect them).  Is there any documentation on what components can talk to each other?
If you could provide me with a sample of what you are proposing that would be greatly helpful.
Thanks