Вы находитесь на странице: 1из 70

Oracle APEX REST

Hands-On Lab

April, 2019 (v19.1 OTN)

Copyright © 2018, Oracle and/or its affiliates. All rights reserved. | 2


Overview
This lab requires two different schemas. On https://apex.oracle.com
each workspace is associated with only one schema.
The first workspace will be where you create the EMP and DEPT
tables and then create REST modules on the tables.
The second workspace is where you will create an application and
define Web Source modules which call the REST services you just
defined in the first workspace.
Note: If you already have a workspace on https://apex.oracle.com
then you can use that for the second workspace {Step 3 below}.
Copyright © 2018 Oracle and/or its affiliates. All rights reserved. |
Getting Started
Obtaining Free Workspaces

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 4


Step 1 – Getting Started

• Go to https://apex.oracle.com
• Click Get Started for Free

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 5


Step 1b – Getting Started

• Click Request a Free Workspace

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 6


Step 2 – Requesting a Workspace

• Enter your Identification details:


– First Name
– Last Name
– Email
– Workspace
{Note: For workspace enter a
unique name, such as first initial
|| last name || _REST , for example
DPEAKE_REST}
• Complete the wizard steps

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 7


Step 3 – Requesting a Second Workspace

• Once you have requested your first workspace

• Request a second workspace by going back to


https://apex.oracle.com {Step 1}
• In Step 2 enter Workspace = first initial || last name || _HOL
{for example DPEAKE_HOL}

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 8


Step 4 – Completing Creation of Workspaces

• Check your email


You should get two emails from
oracle-application-
express_ww@oracle.com within a
few minutes
{Note: If you don’t get an email go
back to Step 1 and make sure to enter
your email correctly}
• For each, click Create Workspace
• Click Continue to Log In Screen
• Reset your password
Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 9
Building your REST end points
Creating Sample Tables and REST Enabling

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 10


Step 1 – Logging In
• Log into your first workspace on https://apex.oracle.com
{ first initial || last name || _REST , for example DPEAKE_REST}
• In the main menu, select SQL Workshop, select Utilities,
click Sample Datasets

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 11


Step 2 – Creating the EMP and DEPT Tables
• On the EMP /DEPT row, click Install

• Click Next
• Click Install Dataset
• Click Exit
{We do not want to create an application directly on the tables}
Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 12
Step 3 – REST Enabling the tables
• In the main menu, select SQL Workshop, click SQL Scripts

• Click Create

• Copy the following URL into a new window in your browser:


{Remember you are on Slide 13 if you click the link directly}
http://www.oracle.com/technetwork/developer-tools/apex/application-express/apex-hol-rest-enable-5478504.txt

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 13


Step 3b – REST Enabling the tables
• In the Script Editor:
– Enter Script Name = Manual REST on EMP and DEPT
– Paste the contents of the file into the body
– Click Run

• Click Run Now


Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 14
Step 3c – REST Enabling the tables
• Results should show 4 statements processed successfully

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 15


Step 4 – Reviewing the REST Services
• In the main menu, select SQL Workshop, click RESTful Services
• Expand Modules; Expand emp.rest; Click on GET

• Copy the Full URL into your clipboard


Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 16
Step 5 – Testing a REST Service
• Open a new tab / window in your browser
• Paste the Full URL

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 17


Information
Running the SQL Script in Step 3 above REST Enables the schema
and also creates modules for the EMP and DEPT tables and the
EMP_DEPT_V view, together with the appropriate handlers.
Alternatively, you could have gone directly to SQL Workshop >
RESTful Services and REST enabled the schema. Then gone to SQL
Workshop > Object Browser, clicked on each table / view and then
selected REST to define the REST services. However, the handlers
created will utilize Data Dictionary lookups each time they are
called. This is less efficient then the manually created services
created in Step 3, especially on apex.oracle.com which has over
20,000 schemas and an extremely large data dictionary.

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 18


Building your App which will be based on the REST Endpoints
Creating the App

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 19


Step 1 – Log into your Second Workspace
• In the top toolbar, click your user name, then click Sign Out

• Click Return to Sign in Page


• Log into your second workspace on https://apex.oracle.com
{ first initial || last name || _HOL , for example DPEAKE_HOL}

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 20


Step 2 – Create an App
• Click App Builder
• Click Create

• Click New Application

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 21


Step 2b – Create an App
• For Name,
enter REST Employees

• Click Create Application

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 22


Linking the REST Service defined in the first workspace
Adding a Web Source for EMP

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 23


Step 1 – Add Web Source for EMP
• Click Shared Components

• Under Data Sources, click Web Source Modules

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 24


Step 1b – Add Web Source for EMP
• Click Create
• Click Next {Default: From Scratch}

• For Web Source Type,


select ORACLE REST Data Services
• For Name
enter REST EMP Source
• For URL Endpoint
enter the REST URI you tested previously
{Similar to https://apex.oracle.com/pls/apex/dpeake_rest/emp/hol/ }
• Click Next
Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 25
Step 1c – Add Web Source for EMP
• Review the Base URL and Service URL Path
• Click Next

• Click Discover
{Authentication Required = No}

• Click Create Web Source

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 26


Step 2 – Adding Operations
• Click REST EMP Source

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 27


Step 2b – Adding Operations
• Notice only the GET and POST
Operations have been added
• Click Add Operation

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 28


Step 2c – Adding Operations
• For URL Pattern, enter :empno
• For HTTP Method, select GET
• For Database Operation, select Fetch single row
• Click Create

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 29


Step 2d – Adding Operations
• Click Add Operation
–For URL Pattern, enter :empno
–For HTTP Method, select PUT
–For Database Operation, select Update row
–Click Create
• Click Add Operation
–For URL Pattern, enter :empno
–For HTTP Method, select DELETE
–For Database Operation,
select Delete row
–Click Create

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 30


Defining the Report and Form on EMP
Creating Pages

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 31


Step 1 – Use the Create Page Wizard
• Return to the Application Home Page
• Click Create Page

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 32


Step 1b – Use the Create Page Wizard
• For Page Type, click Report

• For Report Type, click Report and Form

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 33


Step 1c – Use the Create Page Wizard
• For Report Page Name,
enter Employees
• For Form Page Name,
enter Maintain Employee
• For Form Page Mode,
click Modal Dialog
• For Breadcrumb,
select Breadcrumb
• Click Next

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 34


Step 1d – Use the Create Page Wizard
• For Navigation Preference,
click Create a new navigation menu entry
• Click Next

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 35


Step 1e – Use the Create Page Wizard
• For Data Source, click Web Source
• For Web Source Module, select REST EMP Source
• Click Next

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 36


Step 1f – Use the Create Page Wizard
• For Primary Key Column, select EMPNO (Number)
• Click Create

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 37


Step 2 – Run the Application
• From Page Designer, click Save and Run

• On the Login Page,


enter your user credentials

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 38


Step 2b – Run the Application
• Review the Employees

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 39


Step 2c – Run the Application
• On the Employees report page, click Actions, click Columns

• Shuffle the columns to put EMPNO,ENAME, and DEPTNO as the


first three columns, by selecting the column and using the arrows.
• Click Apply

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 40


Step 2d – Run the Application
• Click Actions, select Report, click Save Report

• For Save, select


As Default Report Settings

• Click Apply

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 41


Step 2e – Run the Application
• Click the edit icon on a row
- The Form Page is displayed
• In the Developer Toolbar,
click Edit Page 3
- Page Designer will be displayed
for the current page
{Note: The Developer Toolbar
is only displayed when you run
apps from App Builder, so is
never visible to end users}

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 42


Step 3 – Update the Page
• In the Rendering tab (left pane), click Column P3_EMPNO
• In the Property Editor (right pane)
- For Type select Number Field
- For Label enter Empno

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 43


Step 3b – Update the Page
• In the Rendering tab (left pane),
click Column P3_JOB
• In the Property Editor (right pane),
for Type select Text Field

• In the Rendering tab (left pane),


click Column P3_ENAME
• In the Property Editor (right pane),
for Type select Text Field
• In the Rendering tree,
drag P3_ENAME up to be under P3_EMPNO

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 44


Step 3c – Update the Page
• In the Rendering tab (left pane), click Column P3_DEPTNO
• Drag P3_DEPTNO up to be under P3_ENAME

• In Layout (middle pane),


select P3_COMM
• Drag it up next to P3_SAL

• In the Toolbar, click Save


Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 45
Step 4 – Insert a Record
• Navigate back to the Runtime environment
• Refresh the browser
• Click Create

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 46


Step 4b – Insert a Record
• For Empno enter 1234
• For Ename enter SMITH
• For Deptno enter 10
• For Job enter CLERK
• For Mgr enter 7839
• For Sal enter 1500
• For Hiredate select any date
• Click Create
• Find the new entry on the
Employees report page
Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 47
Step 5 – Update a Record
• In the report, find Ward, and click the edit icon
• For Sal, enter 1500
• For Comm, enter 750
• Click Apply Changes
• Review Ward in the report

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 48


Step 6 – Delete a Record
• In the report, find Turner, and click the edit icon
• Click Delete
• Click Ok
• Review the report to
ensure Turner is deleted

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 49


Using the REST Service on DEPT
Defining List of Values

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 50


Information
When you ran the script in your first workspace you created a REST
handler for the DEPT table. You can now utilize that REST URI within
a PL/SQL Function by using the APEX_EXEC package.
In order to utilize the APEX_EXEC package you must first define a
Web Source on the REST DEPT Service within this application.
Once fully implemented, you can utilize the function as the basis for
a List of Values against the DEPT table.

Read this blog post for more details:


https://blogs.oracle.com/apex/apex-181-early-adopter-2-rest-services-and-plsql

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 51


Step 1 – Add Web Source for DEPT
• Return to the Application Builder
• Go to the App Builder Home Page
• Select your application
• Click Shared Components
• Click Web Source Modules

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 52


Step 1b – Add Web Source for DEPT
• From Web Source Modules, click Create
• Click Next {Default: From Scratch}

• For Web Source Type,


select ORACLE REST Data Services
• For Name
enter REST DEPT Source
• For URL Endpoint
enter the REST URI for the dept.rest handler
{Similar to https://apex.oracle.com/pls/apex/dpeake_rest/dept/hol/ }
• Click Next
Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 53
Step 1c – Add Web Source for DEPT
• Review the Base URL and Service URL Path
• Click Next

• Click Discover
{Authentication Required = No}

• Click Create Web Source

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 54


Step 2 – Adding a Function to call DEPT
• In the main menu, select SQL Workshop, click SQL Scripts

• Click Create

• Copy the following URL into a new window in your browser:


{Remember you are on Slide 54 if you click the link directly}
http://www.oracle.com/technetwork/developer-tools/apex/application-express/apex-hol-func-5478627.txt

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 55


Step 2b – Adding a Function to call DEPT
• In the Script Editor:
– Enter Script Name = DEPT Function
– Paste the contents of the file into the body
– Click Run

• Click Run Now


Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 56
Step 2c – Adding a Function to call DEPT
• Results should show 3 statements processed successfully

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 57


Step 3 – Add the List of Values
• Return to App Builder
• Select your application
• Click Shared Components
• Click List of Values

• Click Create
• Click Next {Default: From Scratch}

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 58


Step 3b – Add the List of Values
• For Name, enter DEPT LOV
• For Type, select Dynamic
• Click Next

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 59


Step 3c – Add the List of Values
• For Query enter
select dname as d,
deptno as r
from table ( dept_rest )
order by 1
{Note: dept_rest is the name
of the function created in the
previous step}
• Click Create List of Values

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 60


Step 4 – Update the EMP Pages
• Click on Application xxxxx in the breadcrumbs
• Click 2 - Employees

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 61


Step 4b – Update the EMP Pages
• In the Rendering tree (left pane), click Columns, click DEPTNO
• In the Property Editor (right pane)
- For Type, select Plain Text (based on List of Values)
- For List of Values, select DEPT LOV
- For Heading > Alignment, click Start
- For Layout > Column Alignment, click Start

• In the toolbar, click Save

{See the screenshot on the next slide}

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 62


Step 4c – Update the EMP Pages

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 63


Step 4d – Update the EMP Pages
• Navigate to Page 3

• In the Rendering tree (left pane), click P3_DEPTNO


• In the Property Editor (right pane)
- For Type, select Select List
- For List of Values > Type, select Shared Component
- For List of Values, select DEPT LOV
- For Display Extra Values, click No
- For Display Null Value, click No
• In the toolbar, click Save
{See the screenshot on the next slide}
Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 64
Step 4e – Update the EMP Pages

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 65


Step 5 – Run the Application
• Navigate to the application Runtime Environment
• Refresh your browser

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 66


Step 5b – Run the Application
• Click on the edit icon for any record
• Select a department

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 67


Learn More
Useful Links

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 68


Useful Links
• APEX Collateral http://apex.oracle.com
• Tutorials https://apex.oracle.com/en/learn/tutorials
• Hands-on Labs http://apex.oracle.com/hols
• Community http://apex.oracle.com/community
• External Site + Slack http://apex.world

Copyright © 2018 Oracle and/or its affiliates. All rights reserved. | 69

Вам также может понравиться