Search This Blog

Tuesday, July 1, 2025

How do I Create a REST Service from a Table in Oracle APEX

 Introduction

Creating a REST service from a table in Oracle APEX allows developers to expose database data through web services, enabling seamless data exchange with external applications or systems. This approach is essential for building modern, service-oriented applications that rely on lightweight and secure communication. With Oracle APEX and Oracle REST Data Services (ORDS), you can quickly and securely publish your data using a no-code or low-code interface. Whether you are integrating with other systems, feeding a dashboard, or enabling mobile apps, creating a RESTful service is a vital step.

To create a REST service from a table in Oracle APEX, you use Oracle REST Data Services (ORDS), which provides a way to expose your database objects as RESTful web services. This allows you to access and manipulate table data over HTTP. Here is a detailed step-by-step process to create a REST-enabled table service:

  1. Login to Oracle APEX
    Open your Oracle APEX workspace and navigate to the SQL Workshop. Select RESTful Services under the RESTful Services section.

  2. Enable REST for the Schema (if not already enabled)
    Before creating services, you need to ensure that REST is enabled for your schema.

    • Go to SQL Workshop > RESTful Services > RESTful Services Dashboard.

    • Click on Enable RESTful Services for your schema if it shows as disabled.

    • Optionally, define a Schema Alias and a Module Prefix.

  3. Create a New REST Module

    • Go to SQL Workshop > RESTful Services > Modules.

    • Click Create Module.

    • Enter a Name (e.g., employee_api).

    • Provide a Base Path (e.g., /hr/employees/).

    • Optionally, enter a description.

    • Click Next to continue.

  4. Define a Template
    Templates define the URL pattern.

    • Click Create Template.

    • Enter a URI Template like / for all rows or /:id for a specific row.

    • Select the appropriate Method (GET, POST, PUT, DELETE) depending on what you want the endpoint to do.

  5. Create a Handler
    For each method (GET, POST, etc.), define a SQL or PL/SQL block to execute.
    For example, to fetch all rows:

    • Choose Method: GET

    • Source Type: Query

    • Enter a SQL statement such as:

      SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, DEPARTMENT_ID
      FROM EMPLOYEES
      
    • Click Create Handler

    For a specific row:

    • URI Template: /:id

    • Method: GET

    • Source Type: Query

    • SQL:

      SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, DEPARTMENT_ID
      FROM EMPLOYEES
      WHERE EMPLOYEE_ID = :id
      
  6. Add POST, PUT, DELETE Handlers (optional)
    You can add other HTTP methods for inserting, updating, or deleting records:

    • POST for inserts

    • PUT for updates

    • DELETE for deletions
      Use PL/SQL blocks like:

    INSERT INTO EMPLOYEES (EMPLOYEE_ID, FIRST_NAME, LAST_NAME, DEPARTMENT_ID)
    VALUES (:employee_id, :first_name, :last_name, :department_id);
    
  7. Test the REST Service
    After defining your templates and handlers:

    • Go to the Module Overview

    • Copy the full endpoint URL.

    • Use a tool like Postman, or simply paste the URL in your browser if it’s a GET method, to verify the response.

  8. Use Authentication (Optional)
    You can control access using:

    • OAuth2

    • Basic Authentication

    • Oracle APEX session authentication

  9. Consume in APEX Application
    Once your REST service is working, you can use it as a Web Source in APEX.

    • Go to Shared Components > Web Source Modules

    • Create a new Web Source using the REST endpoint.

    • Use it in forms, reports, and interactive grids as a data source.

By following these steps, you enable a table in your Oracle database to be accessed through RESTful services, providing flexible and modern data integration for internal and external applications.

Oracle APEX provides built-in support for creating RESTful web services, allowing applications to expose database tables as RESTful endpoints. This is useful for integrating with external applications, enabling mobile development, and sharing data securely over HTTP.


Why Use REST Services in APEX?

  • Provides an easy way to expose database tables as RESTful APIs.

  • Allows seamless integration with external systems and applications.

  • Supports JSON and XML data formats for modern web applications.

  • Enables mobile and web applications to interact with database data remotely.


Steps to Create a REST Service from a Table in APEX

Step 1: Enable ORDS (Oracle REST Data Services) in APEX

  1. Open SQL Developer or SQLcl and connect to your Oracle Database.

  2. Run the following command to enable ORDS for your schema: 

BEGIN

   ORDS.ENABLE_SCHEMA(p_enabled => TRUE, p_schema => 'MY_SCHEMA', p_url_mapping_type => 'BASE_PATH', p_url_mapping_pattern => 'my_schema', p_auto_rest_auth => FALSE);

   COMMIT;

END;

  1. This enables RESTful services for your schema, allowing you to expose database objects.


Step 2: Create a REST Module in APEX

  1. Log in to Oracle APEX and navigate to SQL Workshop.

  2. Click on RESTful Services.

  3. Click Create and select Module.

  4. Enter a module name, such as employees_service, and set the Base Path (e.g., /employees).

  5. Click Next, then Create.


Step 3: Define a RESTful GET Handler for a Table

  1. Inside the created module, click Create Template.

  2. Set the URI Pattern as /:id?, allowing retrieval of all or a single record.

  3. Click Next, then Create.

  4. Click Create Handler and select Method: GET.

  5. In the Source Type, select SQL Query and enter: 

SELECT * FROM employees WHERE employee_id = :id OR :id IS NULL;

  1. Click Next, then Create.

  2. Test the REST endpoint by opening a browser and entering: 

https://your-apex-url/ords/my_schema/employees/

This should return a JSON response with all employees.

  1. To fetch a specific employee, use: 

https://your-apex-url/ords/my_schema/employees/100

This returns details for employee ID 100.


Step 4: Create a RESTful POST Handler to Insert Data

  1. Inside the REST module, create another Template with the same URI Pattern (/).

  2. Click Create Handler, select Method: POST, and set the Source Type to PL/SQL.

  3. Enter the following PL/SQL block to handle inserts: 

BEGIN

   INSERT INTO employees (employee_id, first_name, last_name, email, hire_date, job_id)

   VALUES (:employee_id, :first_name, :last_name, :email, SYSDATE, :job_id);

   COMMIT;

END;

  1. Click Create, then test the API using a REST client like Postman or cURL

curl -X POST -H "Content-Type: application/json" -d '{"employee_id":101, "first_name":"John", "last_name":"Doe", "email":"jdoe@example.com", "job_id":"IT_PROG"}' https://your-apex-url/ords/my_schema/employees/

  1. This inserts a new employee record into the employees table.


Step 5: Create a RESTful PUT Handler to Update Data

  1. Create a new Template with URI Pattern /:id.

  2. Click Create Handler, select Method: PUT, and enter: 

UPDATE employees

SET first_name = :first_name, last_name = :last_name, email = :email, job_id = :job_id

WHERE employee_id = :id;

COMMIT;

  1. Test with: 

curl -X PUT -H "Content-Type: application/json" -d '{"first_name":"Jane", "last_name":"Smith", "email":"jsmith@example.com", "job_id":"HR_REP"}' https://your-apex-url/ords/my_schema/employees/101

  1. This updates the employee record for ID 101.


Step 6: Create a RESTful DELETE Handler

  1. Create a new Template with URI Pattern /:id.

  2. Click Create Handler, select Method: DELETE, and enter: 

DELETE FROM employees WHERE employee_id = :id;

COMMIT;

  1. Test by running: 

curl -X DELETE https://your-apex-url/ords/my_schema/employees/101

  1. This removes the employee with ID 101 from the table.

Conclusion
Publishing a REST service from a table in Oracle APEX is straightforward and powerful. With just a few configuration steps, you can expose your table's data to any authorized consumer, all while maintaining control over access and structure. Oracle APEX and ORDS provide a secure and scalable framework for RESTful development, making it easy to build API-driven applications that work seamlessly across platforms.

How do I Integrate REST Data Sources into APEX Components

 Introduction

In Oracle APEX, integrating REST Data Sources into components such as reports, forms, and charts enables developers to seamlessly pull in external data from web services and APIs. This feature is especially powerful for building applications that rely on real-time or external systems, without needing to store all the data locally. With REST-enabled SQL and APEX’s declarative tools, incorporating REST data into your components is both flexible and efficient.

In Oracle APEX, integrating REST Data Sources into APEX components allows your applications to fetch and display external data without requiring the data to be stored in your local Oracle database. This is especially useful when working with third-party services, microservices, or remote Oracle REST-enabled SQL services.

To begin, navigate to Shared Components > REST Data Sources. Here you can define a new REST Data Source by clicking Create. Choose between a Web Source (for generic REST APIs) or REST Enabled SQL (for Oracle REST Data Services). Enter the endpoint URL, authentication method (such as OAuth2, basic auth, or no authentication), and any required headers or parameters. You can preview the data to ensure the connection is successful.

Once the REST Data Source is created, it becomes available for use in your APEX application just like a local table or view. You can now go to Create Page > Report and select REST Data Source as the data source. APEX will prompt you to select from available REST definitions and map JSON or XML fields to report columns. You can also use REST Data Sources in Forms, Charts, or Interactive Grids, and even combine them with local data using REST-enabled SQL when needed.

APEX also provides flexibility to work with REST data in PL/SQL using APEX_WEB_SERVICE API, allowing developers to manipulate or process data before rendering it on a page. Additionally, you can apply pagination, filtering, and transformations directly within the REST Source definition or on the component consuming it.

Using declarative settings and low-code configuration, Oracle APEX makes it easy to integrate RESTful services directly into your applications, empowering developers to build rich, dynamic interfaces that consume data from any web-accessible source.

Once a REST Data Source is established, it can be utilized in various APEX components:

  • Reports: Both Classic and Interactive Reports can display data from REST Data Sources.

  • Charts: JET Charts can visualize data retrieved from RESTful services.

  • Calendars: CSS Calendars can present date-related information from external sources.

To integrate a REST Data Source into a component:

  1. Create or Edit the Component:

    • In the App Builder, create a new component (e.g., report, chart) or edit an existing one.

  2. Select the Data Source:

    • In the component's settings, choose REST Data Source as the data source type.

    • Select the previously created REST Data Source.

  3. Configure Component Attributes:

    • Define attributes such as columns to display, filters, and sorting options based on the data provided by the REST service.

Conclusion
By integrating REST Data Sources into APEX components, you expand your application’s capabilities to consume and present data from any accessible REST API. This approach empowers your apps to become more dynamic and connected, all while taking advantage of APEX’s low-code environment. Whether displaying live data in reports or creating interactive forms that fetch and send data via REST, Oracle APEX provides the tools to build modern, data-rich applications with ease.

How do I Configure General Settings

 Introduction

Configuring general settings in Oracle APEX is an essential step in tailoring your application’s behavior, appearance, and core attributes. These settings govern foundational aspects such as the application’s name, language, authentication method, session state behavior, and debugging options. Whether you're starting a new project or enhancing an existing one, understanding how to properly configure general settings ensures a smoother development process and a more robust, user-friendly application.

In Oracle APEX, configuring general settings allows developers to define application-wide parameters that influence the core behavior, security, and user interface. These settings are crucial for establishing how the application will operate at runtime.

To configure general settings in Oracle APEX, follow these detailed steps:

  1. Open the APEX App Builder
    Navigate to the APEX workspace and open the application you want to configure. Once inside the App Builder, click on the application name to open the Application Definition page.

  2. Access General Settings
    On the left-hand side, locate the "Shared Components" section. Within that section, scroll down to the "Application Definition" area and click on "Edit Application Definition". This will lead you to the general settings.

  3. Edit Application Properties
    Here you will see multiple tabs such as:

    • Name and ID

    • Application Attributes

    • User Interface

    • Security

    • Globalization

    • Compatibility
      Each of these tabs contains important configuration settings.

  4. Set Application ID and Name
    On the first tab, define the Application ID (automatically generated, but customizable) and set a meaningful Application Name that will be displayed to users.

  5. Configure Authentication
    Under the "Security" tab, choose the authentication scheme such as APEX accounts, LDAP, or Single Sign-On. This defines how users will log in to your application.

  6. Set Authorization Schemes
    Still in the Security tab, assign any predefined or custom authorization schemes to control access to pages, components, or data.

  7. Globalization and Language Settings
    In the "Globalization" tab, set the application’s language, date format, timestamp format, and territory. This ensures data is presented appropriately based on regional settings.

  8. Application Timestamp Settings
    Configure the default timestamp and date formats to be used across pages and components.

  9. Debugging and Feedback
    Enable or disable debugging, and configure developer toolbar access. These settings are helpful during testing and production troubleshooting.

  10. Define Session State Management
    Under "Application Attributes", configure how session state should be maintained. This includes cookie settings, URL session IDs, and session timeouts.

  11. Compatibility Settings
    Use this section to control behavior changes between APEX versions. This is useful when upgrading applications across versions to maintain compatibility.

  12. Save Changes
    Once you have made all necessary adjustments, click the "Apply Changes" button at the top or bottom of the screen.

By carefully managing these settings, you can ensure your Oracle APEX application is secure, user-friendly, and aligned with your business requirements. These configurations are foundational and should be reviewed at the start of development and whenever major changes are introduced.


  • REST Data Source Type: Select the appropriate type based on your data source (e.g., Simple HTTP, ORDS).

  • Name: Provide a descriptive name for the data source.

  • URL Endpoint: Enter the full URL of the REST service, starting with http:// or https://.

A screenshot of a computer

AI-generated content may be incorrect.

  1. Define Remote Server Details:

    • Remote Server: Choose an existing Remote Server or define a new one.

    • Base URL: Specify the base URL of the remote server.

    • Service URL Path: Indicate the specific path to the REST service on the server.

A screenshot of a computer

AI-generated content may be incorrect.

  1. Set Pagination (if applicable):

    • Depending on the REST Data Source Type, select the pagination method, such as Page Size and Fetch Offset.

  2. Authntication Required

A black background with white text

AI-generated content may be incorrect.

Finalizing the Creation:

  • Choose to create the REST Data Source manually or use the Discover option to let APEX analyze the service and derive a data profile.


A screenshot of a computer

AI-generated content may be incorrect.



A screenshot of a video game

AI-generated content may be incorrect.

Conclusion
By configuring general settings thoughtfully, you lay a solid foundation for your Oracle APEX application. These settings affect how users interact with your app, how data flows through sessions, and how the overall interface responds. Taking the time to review and fine-tune general settings helps you maintain consistency, optimize performance, and better support user needs as your application evolves.

HOW DO I SET A HOME PAGE

 Setting a home page in Oracle APEX is an essential step in defining the default landing page for your application. The home page serves as ...