Wednesday, October 28, 2015

ADF 12.2.1 ADF BC Support for REST

ADF 12.2.1 provides out of the box support for REST. You should read about all available REST functionality in ADF BC here - 16 Creating RESTful Web Services with Application Modules. I have created very quick sample application to test how it works.

Before generating REST on top of ADF BC, you must configure release version for REST. This can be any number:


To generate REST, go to REST Web Service interface in Application Module and add new REST resource. Here you can select VO and provide REST resource name:


JDeveloper generates REST resource where you could configure attributes to expose, custom methods, etc.:


As soon as you generate REST resource on top of ADF BC, JDeveloper creates new project with web.xml. You could use this project to run/test REST (simply right click and choose Run to test on integrated WLS):


I can test REST through URL: http://127.0.0.1:7101/restapp/rest/1/Employees, ADF returns well structured REST response:


ADF is smart to return only a subset of data, it offers a parameter to control how many rows to fetch in a single call, it also shows if there are more rows to be returned in the result set:


I can set limit parameter to retrieve only one row, this is how it works:


Download implemented sample application - ADFBCRestApp.zip.

12 comments:

Unknown said...

Hi Andrejus,

How can I retrive all rows in a single call with out using limit parameter.

Regards,
Vikram

Andrej Baranovskij said...

Try to use limit = -1 or set -1 for Range Size in ADF BC REST collection definition.

Regards,
Andrejus

Daniel said...

Hi Andrejus,

How can I change the connection to my Database, but instead of using a direct connection (Business Components) using a Weblogic DataSource?

Thanks
Daniel

Andrej Baranovskij said...

You can type Data Source name into AM config (use Data Source in ADF BC).

Regards,
Andrejus

Daniel said...

Only that?
In previous version I had to remove the connection, change bc4j and web.xml files to reference the datasource.

By any chance do you have any step by step?

Thanks
Daniel

Andrej Baranovskij said...

Yes, is pretty simple in new versions. You dont need to remove connection or change anything in bc4j or web.xml. I think it is documented in ADF developer guilde.

Andrejus

Unknown said...

Hi Andrejus,

Is it possible to create Rest webservice on top of ADF BC using programmatic VOs which won't be having any EO?

Thanks,
Pallavi

Andrej Baranovskij said...

Yes, ADF BC REST is using VO's, it doesnt require EO.

Andrejus

crockkaw said...

Hi!
Great tutorial :)
But I need help...

How to add a where clause ?
For example all rows from database with Sallary = 25000 ?

Best regards,
Charles

Andrej Baranovskij said...

Hi,

You can use ADF BC REST query params in REST URL request.

If you are using bind variables in VO, here is another solution: http://andrejusb.blogspot.lt/2017/01/sql-bind-variable-support-in-adf-bc-rest.html

Regards,
Andrejus

Zameer Abdu Kadar said...

is there any example for POST method.
When i am trying , it's always showing the response code 415 Unsupported Media type.
I copy the json payload from get result for a record and change the values and used that as the payload in the POST, i also added the content type as json, (also copied from the get result). But still showing the same response.

Any help on this

zam

Andrej Baranovskij said...

Yes, check this post: http://andrejusb.blogspot.lt/2015/12/crud-with-adf-1221-adf-bc-rest.html

You need to provide Content-Type, see example.

Andrejus