Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

JSON Data Services

DZone's Guide to

JSON Data Services

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

Want to specify an SQL statement and a corresponding URI pattern, and create a RESTful JSON Data Service with just one line of configuration?

The Free and Open Source UltraESB v1.3.0 introduces JSON Data Services which does exactly this! Create data services by specifying a SQL query and a URI pattern. The URI patterns allows you to specify variables, that correspond to the SQL statement as shown in the following example.

URI Pattern:  /byDeptAndDivision/{department:INTEGER}/{division:INTEGER}?{age:INTEGER},{sex:VARCHAR}

SQL: select * from employee where division = :division and department = :department and sex = :sex and age > :age

The results of the SQL are converted into a JSON response and returned. Read the full article that shows many examples with a hypothetical employee database.

 Your configuration for the above mentioned RESTful JSON Data Service maybe as simple as shown below:

<u:proxy id="basicEmployeeService">
<u:transport id="http-8280"/>
<u:target>
<u:inSequence>
<u:java><![CDATA[
mediation.processBasicJSONDataServiceRequest(msg, "empJsonSvc", "dataSource");
]]></u:java>
</u:inSequence>
</u:target>
</u:proxy>

<bean id="empJsonSvc" class="org.adroitlogic.ultraesb.core.helper.BasicJSONDataService" init-method="init">
<property name="queryMap">
<map>
<entry key="/getPermanentEmployees" value="select * from employee where permanent = 1"/>
<entry key="/byDeptAndDivision/{department:INTEGER}/{division:INTEGER}?{age:INTEGER},{sex:VARCHAR}"
value="select * from employee where division = :division and department = :department and sex = :sex and age > :age"/>
</map>
</property>
</bean>

Now, issuing a GET request such as : 

GET http://localhost:8280/service/basicEmployeeService/byDeptAndDivision/2/3?age=20&sex=male

will get you the result set as JSON. (Note that the service context path, service name or URL pattern can be customized as required)

[{"EMPLOYEEID":1,"EMPLOYEENAME":"tom","AGE":35,"DEPARTMENT":2,"DIVISION":3,"SALARY":34500.0,"SEX":"male","PERMANENT":0,"ADDRESS":"milano","DATEOFBIRTH":"1975-02-23"},
{"EMPLOYEEID":3,"EMPLOYEENAME":"nancy","AGE":39,"DEPARTMENT":2,"DIVISION":3,"SALARY":22342.0,"SEX":"male","PERMANENT":1,"ADDRESS":"london","DATEOFBIRTH":"1971-05-14"}]

The UltraESB supports the creation of REST services that updates the database as well using the HTTP PUT, POST and DELETE methods.

Read the full article that shows the creation of multiple functions for a JSON Data Service at the AdroitLogic web site

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}