Oracle Database Cloud Service with the Database as a Service option comes preconfigured with Oracle APEX and Oracle REST Data Services. These features can be used to easily create and interact with RESTful Web Services. This example is based on a specific customer requirement, however it can be useful across a range of options with RESTful Web Services. The customer had the task at hand to access RESTful Web Services using PL/SQL. The main reason for this was being able to integrate the RESTful Web Services in their existing PL/SQL applications and use them across a range of other Java Applications without the need to create a separate interface. This example is based on the RESTful services that have been created as part of this post.
Follow the steps outlined in this post. For this example you will need to create the GET and POST Resource handlers.
In order to access the RESTful Web Service the traffic to port 80 has to be enabled for the Database Cloud Service Instance. For this example traffic will only be allowed from a specific IP address. To achieve this navigate the Oracle Compute Cloud Service Console – click on the Network tab and click the Security IP Lists button on the left hand side.
Clicking the “Create Security IP list” button opens the a dialog where a meaningful name and desription plus the IP address that will access the service needs to be entered. Finish by clicking “Create”.
The next step is to create a Secuity list. Select the “Security Rules” button on the left hand side and click the “Create Secuity Rule” button on the right.
This opens a dialog where a Name needs to be entered. Make sure to select “Enabled” for status and select the previously created Security IP List as source and select your DBCS instance as Destination. For this example select the out-of-the-box Security Appliaction http – this will open up Port 80. Finish by clicking “Create”.
For easier access to the database I also created a rule to allow traffic on port 1521. Security application: ora_dblistener (Port 1521). This allows to directly access the database from the target IP.
Accessing the RESTful Web Service is straight forward. Make sure to replace the <dbcs-ip> tag with the public IP of your Database Cloud Service Instance. This public IP can be found on the Overview Page of the Oracle Database Cloud Service Console.
This will return the data that has previously been created in the example here. Using SQL*plus will print the returned JSON via the dbms_output.put_line procedure.
apex_web_service.make_rest_request also allow to submit data into a RESTful Web Service using the POST method. The following script allows using the POST Resource Handler to submit data into the Instance. apex_web_service.g_request_headers allows submitting headers as part of the request.
After submitting the above call the data can be verified be using the GET method – same as previously:
Or alternatively we can query the target table directly – for example using the APEX GUI.
Application Express API Reference - APEX_WEB_SERVICE
Oracle REST Data Services Documentation