Oracle APEX Blog

APEX REST Enabled Forms

Written by Colin Archer | Sep 4, 2020 12:43:46 PM
Find out how we can help you build solutions using Oracle APEX with our award winning application development and consultancy services.

Following on from my previous blog, today I am going to take a look at the REST enabled form improvements first introduced in APEX 19.1. It is now possible to declaratively create an APEX form based on Web Service using a Web Source Module. I will also take the opportunity to demonstrate REST enabled objects, which allow you to easily REST enable tables, views, packages, procedures and functions.

For this demonstration I will be using APEX version 20.1 on an apex.oracle.com workspace and the OEHR_JOBS table from the HR Data sample dataset.

Prerequisites

Before starting you will need to complete the following prerequisite tasks.

  1. Install the HR Data sample dataset into your schema (SQL Workshop > Utilities > Sample Datasets).
  2. Ensure your schema is registered for ORDS (SQL Workshop > RESTful Services).

REST Enabled Objects

Before we can create a REST enabled form, we need to create a RESTful Web Service over a data source. One of the simplest ways to do this is to use the REST Enabled Object feature which can be accessed via the SQL Workshop.

  1. Open the SQL Workshop and Select Object Browser.
  2. Select the table OEHR_JOBS.
  3. Click on the REST tab and use the following settings:
REST Enabled Object Yes
Object Alias jobs
Authorisation Required No
  1. Click Apply.

You will see a success message meaning that the table has been REST enabled, complete with HTTP methods for GET, PUT, POST and DELETE.

The RESTful URI will now be displayed.

 

  1. Copy the RESTful URI, paste it into a new browser window and press ENTER.

The GET Web Service is called and data from OEHR_JOBS is returned to the browser in JSON format. In the above example the JSON text has been formatted using a browser extension. If you are not using one there are many free online formatting tools available.

  1. Select RESTful Services from the SQL Workshop menu.
  2. Select Enabled Objects from the RESTful Data Services tree.

You will see objects that the table have been enabled for REST, which in this example is just the table OEHR_JOBS.

Web Source Module

Now we have a suitable Web Service we can use for a REST Enabled Form we can create the Web Source Module.

  1. Return to the App Builder and open your application.
  2. From Shared Components select Web Source Modules within the Data Sources area.
  3. Click CREATE and select From Scratch.
  4. Click Next and use the following settings:
Web Source Type Oracle REST Data Service
Name Jobs
URL Endpoint The RESTful URI you copied

We can select the Oracle REST Data Service option because we are using a Web Service generated by REST enabling a table, so we know it follows the Oracle REST standard and has GET, PUT POST and DELETE operations.

  1. Click Next.
  2. Keep the Remote Server defaults and click Next.
  3. We are not using authentication in this example, so leave it turned off and click Discover.
  4. Sample data and the data profile are returned. Review and then click Create Web Source.

The Web Source Module has now been created.

Click on the newly created Web Source Module to open the details and scroll down to Operations.

You can see that the operations we required for the REST Enabled form have all been added automatically.

REST Enabled Form

We can now create a linked report and form using the Jobs Web Source Module.

  1. Return to the application builder home page and click on Create Page.
  2. Click on Form.
  3. Click on Report with Form and use the following settings:
Report Type Interactive Report
Report Page Name Jobs
Form Page Name Job Details
For Page Mode Modal Dialog
  1. Select the option to create a new navigation entry if you wish and click Next.
  2. Use the following settings for the data source.
Data Source Web Source
Web Source Module Jobs
Report Columns Keep the default of all columns selected
  1. Click Next and use the following settings for the form page:
Form Columns Keep the default of all columns selected
Primary Key Column JOB_ID
  1. Click Create and the click on the Save and Run Page button.APEX has created an Interactive report with a linked form using the Web Service we created over the OEHR_JOBS table which we can use to query, update, insert and delete. This has all be done declaratively using standard APEX components.

  1. Test the form by creating, updating and deleting some jobs.
  2. While on the form page, click Edit Page on the developer toolbar and take a look at how the page has been built by APEX.

If you take a look at the Job Details region you will see it is a Form Region with the data source set to the Jobs Web Source we created.

Take a look at the processing APEX has created and you will see it uses the Form Automated Row Processing (DML) type.

 

Need some help with your APEX applications? Speak to the experts today.

Author: Colin Archer 

Job Title: Senior Oracle APEX Development Consultant

Bio: Colin is a Senior Development Consultant at DSP-Explorer with 20 years’ experience of analysis, design, and development of bespoke Oracle applications for a wide variety of business functions. Building on his previous experience of Forms and PL/SQL he is now focusing on developing high quality fit for purpose solutions using APEX.