Oracle REST Data Services (ORDS) provides a convenient way to expose your Oracle Database resources as RESTful services. This allows you to interact with your database using HTTP methods.
In this blog, we will walk you through the steps to expose ORDS service which is a software that sits on the top of database.
First, we will install ORDS and configure it with the database, then we will show how to expose tables or objects as REST service.
Step 1: Install ORDS
If you haven’t already installed ORDS, you can download it from the Oracle website and follow the installation instructions for your platform.
Step 2: Configure ORDS
After installation, you need to configure ORDS to connect to your Oracle Database. This involves creating a configuration file (usually named ords-config.xml) where you specify database connection details, authentication settings, and the base path for your RESTful services.
Here’s a basic example of an ords-config.xml file:
<ords-config>
<database>
<connectString>jdbc:oracle:thin:@localhost:1521:XE</connectString>
<servletPath>/ords</servletPath>
<admin>
<useDefaultCredentials>true</useDefaultCredentials>
</admin>
</database>
</ords-config>
Step 3: Deploy ORDS
Once you have configured ORDS, you can deploy it to your application server (e.g., Tomcat, WebLogic). This typically involves deploying the ORDS.war file to your server’s deployment directory.
Step 4: Enable RESTful Services
After deploying ORDS, you can enable RESTful services for your database objects (tables, views, procedures, etc.) using the ORDS SQL Developer extension or the SQL*Plus command line.
For example, to enable RESTful services for a table named EMPLOYEES, you can use the following SQL command:
BEGIN
ORDS.ENABLE_OBJECT(p_enabled => TRUE,
p_schema => ‘TEST_SCHEMA’,
p_object => ‘EMPLOYEE’,
p_object_type => ‘TABLE’,
p_object_alias => ’employees’);
END;
Step 5: Test your service
Once you have enabled RESTful services, you can test them by accessing the base path you specified in your ords-config.xml file. For example, if your base path is /ords, you can access the service for the EMPLOYEES table at http://localhost:8080/ords/hr/employees.
Exposing ORDS services allows you to interact with your Oracle Database using RESTful APIs, providing a flexible and scalable way to access your data. By following the steps outlined in this blog, you can easily expose your database resources as RESTful services using ORDS.
Next, we will see how to expose tables or objects as REST service.
Step 1: Right click on employee table, you will see a bunch of options available as shown in the image below.
Step 2: Click on Enable Rest Service, this would open a dialog then follow the below instructions.
Step 3: In the dialog box, it is asking to give your object a name, just give any alias. This alias will be added in your ORDS hosted endpoint to access the REST methods and choose for the authorization required or not.
Also Read: Dynamic Updation of OIC Lookups Using Rest API
Step 4: Now click on next, in this dialog you can see summary and if you click on SQL, you would be able to see the same code as we have seen when we were exposing from the command line. This dialog is next to below dialog box.
Also Read: How to Call Schedule Integrations in OIC using REST API?
Now click on Finish.
So, your table is exposed to the world. Now you can get the URL for that just by taking endpoint of your hosted ORDS and then, adding your table name at the end of the URL, like url/employee.
If you have any questions or concerns, please let us know in the comments or get in touch with us on [email protected].