create restful services using ords (oracle rest data services)days+2018/... · for the oracle...
TRANSCRIPT
Create RESTful Services using ORDS (Oracle Rest Data Services)
a training days march 21-22, 2018 s a It la ke city, UT
Presented by: King Training Resources, LLC - All Rights Reserved
Copyright © 2018, King Training Resources, LLC 1 http://www.kingtraining.com
Session Objectives
• Understand the capabilities of Oracle Rest Oata Services (OROS)
• Learn how OROS makes Oracle data available via standard APls
• Use Oracle data using OROS calls
Copyright © 2018, King Training Resources, LLC 2 http://www.kingtraining.com
Who Am I? • John King - Partner, King Training Resources
A
• Oracle Ace Director _ OakTab\e®
• Member Oak Table Network -rT • I help customers use technology through training and consulting in Oracle and other topics (http://www.kingtraining.com )
• "Techie" who knows Development, Java, Oracle, and SQl along with many other topics
• Member of AZORA, ODTUG, IOUG, and RMOUG rl1tJi
• One of those "dog-spoiling" people Copyright © 2018, King Training Resources, LLC 3 http://www.kingtraining.com
King Training Resources • Providing customized training solutions since 1988 in the US and
internationally • Oracle topics include: SQl, Pl/SQl, Cloud, APEX, ADF, MAF,
Forms, Pro*C/Pro*COBOl • Non-Oracle topics include: UX, Web Services, loT, Cloud Foundry,
REST, Blockchain, Java, JavaScript, HTMl5, CSS, jQuery, COBOL, .NET, SQl Server, DB2, Business Analyst, and more
• Visit us at www.kingtraining.com for information and free downloads of presentations and code
• Contact Peggy at 1.303.798.5727 to schedule training today (email: [email protected] )
Copyright © 2018, King Training Resources, LLC 4 http://www.kingtraining.com
Copyright © 2018, King Training Resources, LLC
Arizona, USA
5 http://www.kingtraining.com
o RACLE® ( ACE PROGRAM
ORACLE- AC E Di recto r
ORACLE ACE
ORACLE- ACE Associate
3 Membership Tiers bit.1y/OracleACEProgram Connect: • Oracle ACE Director • OracieACE • Oracle ACE Associate
~ oracle-ace [email protected] o Facebook.comloracleaces o @oracleace
ORACLE· Developer Community
Nominate yourself or someone you know: acenomination.oracle.com Copyright (Q 2Ul~, King 'Irammg Resources, LLC 6 http://www.kingtraining.com
Who Are You? • Appl ication Developer • DBA • Business Analyst • Other?
Copyright © 2018, King Training Resources, LLC 7 http://www.kingtraining.com
The Crown Jewels • Data; your Crown Jewels
- Today's Apps Built with Polyglot of Tools - Developers don't know SQL or PL/SQL - Applications need to display data
• Data gets dumped to flat files or spreadsheets then made available to apps
• Aaargh! What just happened to all of my planning and investment in thick database?
Copyright © 2018, King Training Resources, LLC 8 http://www.kingtraining.com
Developer Expectations • Today's Developers juggle many tools in an ever-changing landscape - SQL and PL/SQL are not high on their list of desired skills
• Expectations for Data Access - Web Services using RESTful APls - Data input and output using JSON
Copyright © 2018, King Training Resources, LLC 9 http://www.kingtraining.com
REST • REST (Representational State Transfer) describes a different architecture than SOA (the term REST originated in a doctoral dissertation about the web written in 2000 by Roy Fielding - Google it for more ... )
Copyright © 2018, King Training Resources, LLC http://www.kingtraining.com
What? • REST implements Web Services using a simpler technology stack than SOAP
• The term REST is often used to (loosely) describe transmission of domain-specific data via HTTP without SOAP or any type of session tracking
• REST allows execution of Java Web Services using simple HTTP technology without the need of SOAP and WSDL
Copyright © 2018, King Training Resources, LLC 11 http://www.kingtraining.com
How RESTful APls Work • RESTful APls work with resources not procedures
- Resources are uniquely identified by URI - HTTP verbs act on resources in a standard way:
• GET Query • PUT Create (sometimes Update) • POST Update (sometimes Create) • PATCH Partial Update • DELETE Delete
Copyright © 2018, King Training Resources, LLC 12 http://www.kingtraining.com
You Already Know REST --
• One of the strengths of (what we call) REST is that you al ready use it everyday - You use a browser to access a "resource"
http://my.website.com/zebra/i ndex. html • URI includes website or IP address • "resource" (zebra above) • "resource" web page (index.html above)
- You "GET" the data corresponding to the URI
Copyright © 2018, King Training Resources, LLC 13 http://www.kingtraining.com
REST in Action • URLs use nouns for resources (not verbs for actions) GET /ords/hr/employees/ Preferred GET /ords/hr/GetAIIEmployees/ Not Preferred
• Uniform API for operations: GET, POST, PUT, DELETE
• Requests are stateless, state information is contained in URI's (as Oracle's Jeff Smith says, "it's all about the hyperlinks")
Copyright © 2018, King Training Resources, LLC 14 http://www.kingtraining.com
REST Error Code Families
Copyright © 2018, King Training Resources, LLC
Informational
Success
Redirection
Client Error
Server Error
15 http://www.kingtraining.com
Web Services • What is a Web Service anyway? Here's a definition from the W3C (World-Wide Web Consortium) website:
"A Web service is a software application identified by a URI, whose interfaces and binding are capable of being defined, described and discovered by XML artifacts and supports direct interactions with other software applications using XML based messages via internet-based protocols"
Copyright © 2018, King Training Resources, LLC 16 http://www.kingtraining.com
Web Service Payloads • Web Services interactions were originally XML-based but JSON-based interactions are pretty much the standard for Mobile - Plain-text of XML and JSON makes them ideal for cross language/platform use
- Using XML or JSON with standard interfaces like SOAP and REST makes Web Services potentially programming language and operating system independent
Copyright © 2018, King Training Resources, LLC 17 http://www.kingtraining.com
Emergence of JSON • JSON (JavaScript Object Notation) has become the mechanism of choice for sharing and passing data to-and-from mobile applications
• JSON is an international, open standard governed by the ECMA
http://www.ecma- international. org/pu bl ications/fi les/E CMA ST/ECMA-404.pdf
Copyright © 2018, King Training Resources, LLC 18 http://www.kingtraining.com
JSON-XML Similarities • JSON is text only, just like XML and thus is an excellent vehicle for data interchange
• JSON and XML are "human readable" and "self-describing" (sort of ... )
• JSON and XML are hierarchical (data sets nested within data sets)
• JSON and XML offer validation capability; XML's is more mature and capable today
Copyright © 2018, King Training Resources, LLC 19 http://www.kingtraining.com
• JSON-XML Dissimilarities n
• XML is verbose, JSON is less-verbose • JSON has no end tags, required in XML • JSON is quicker to read and write • Reading XML documents requires "walking the DOM" - JSON does not
• JSON works more easily and is faster than XML when working with AJAX
• XML documents must be tested for "well-formed"-ness before processing
Copyright © 2018, King Training Resources, LLC 20 http://www.kingtraining.com
XML File <?xml version="l.O"?>
<myBooks>
<book>
<name>Learning XML</name>
<author>Eric T. Ray</author>
<publisher>O'Reilly</publisher> </book>
<book>
<name>XML Bible</name>
<author>Elliotte Rusty Harold</author>
<publisher>IDG Books</publisher> </book>
<book>
<name>XML by Example</name>
<author>Sean McGrath</author> </book>
</myBooks>
Copyright © 2018, King Training Resources, LLC 21 http://www.kingtraining.com
JSON File { "myBooks" :
[ {"book": { " name" : "Learning XML", "author" : "Eric T. Ray", "publisher":"O'Reilly" }
} , { "book": {
"name" : "XML Bible", "author": "Elliotte Rusty Harold", "publisher": "IDG Books" }
} , { "book": {
" name" : "XML by Example", "author": "Sean McGrath", "publisher":"Prentice-Hall" }
}
] } Copyright © 2018, King Training Resources, LLC 22 http://www.kingtraining.com
Why ORDS? • What if you could expose your Tables, Views, and stored PL/SQL (thick database) as web services?
• What if you could accept input in JSON and generate JSON easily?
• What if you could make data available to today's developers safely in a form they're familiar with and want to use?
Copyright © 2018, King Training Resources, LLC 23 http://www.kingtraining.com
ORDS to the Rescue! • Oracle's Object REST Data Services (ORDS) provides a solution to: - Expose Tables/Views via REST APls
- Expose PL/SQL via REST APls
- Transfer data using JSON or other datatypes
Copyright © 2018, King Training Resources, LLC 24 http://www.kingtraining.com
Introduction to ORDS • Provides RESTful access that modern tools expect • Maps SOL to REST style HTTP: GET, POST, PUT, DELETE
• May return results in JSON (or other data types)
Copyright © 2018, King Training Resources, LLC 25 http://www.kingtraining.com
What is ORDS?
• ORDS is included in Oracle DBaaS instances
• ORDS may be installed easily in any instance
• ORDS runs in any Java EE container (Weblogic, Glassfish, Tomcat, etc.)
• Developers may create standalone version • ORDS is an enhanced version of Oracle's Java mod_plsql Apache module
Copyright © 2018, King Training Resources, LLC 26 http://www.kingtraining.com
Oracle REST Data Services
II ••
I •
~I ::.,. II
III
Oracle REST Data Services
HTTP(S) client Oracle Database
• Data stored in Oracle (relational tables and columns) • ORDS defines URI-to-SQL mapping with SQL results
mapped to JSON (or other data types) • Applications use URis via HTTP(S) to GET and POST
data Copyright © 2018, King Training Resources, LLC 27 http://www.kingtraining.com
Oracle REST Data Services 3.0
1. Browser RESTful GET request /
http://my. host.server/ords/hr/employees/1 0 2. ORDS maps to "EMPLOYEES" SOL
SELECT * FROM EMP WHERE DEPTNO = :b1
3. SOL Calt OVer JOBC
~. DB returns JOSC Resu\ts Browser Weblogic,
Glassfish, Tomcat, other
container
• ORDS is an improved version of the original mod_plsql • ORDS maps requests to SQL and transforms results to JSON (or CSV, Text, Binary, Excel, more ... )
• Mappings are automatic or created using SQL Developer Copyright © 2018, King Training Resources, LLC 28 http://www.kingtraining.com
ORDS REST APls
POST
DELETE
HEAD
Copyright © 2018, King Training Resources, LLC
'Read' a resource
'Create' a resource
'Update or Create'
'Delete' a resource
'Read' resource headers
29 http://www.kingtraining.com
Typical REST "Payload" { " items": [
{
"employee_id": 100,
"first name": " Steven" ,
"last name": "King",
"email": "SKING" , "phone_number": "515.123.4567",
"hire_date": "1987-06-17T04:00:00Z",
"job _ id" : "AD_PRES",
"salary": 24000,
"commission_pct": null,
"manager_id": null,
"department_id": 90,
" links": [
.... More Here Copyright © 2018, King Training Resources, LLC } , 30 http://www.kingtraining.com
ORDS Installation • I nstallation is easy with SOL Developer
Copyright © 2018, King Training Resources, LLC
~ Database Copy ... Database Diff. Database Export. .. Migration .... Monitor SOL ... Monitor Sessions ...
~ SQL Worksheet \:: F10 -----------
Unit Test ....
Window Help
Data Modeler
Data Miner ....
OLAP ....
REST Data Services ....
External Tools ...
Features ...
2016/Conferences/OTN NordicTou
with_test_1.sql 1[00 ,
Manage Connections ..
Run ...
Install... Uninstall ...
31 http://www.kingtraining.com
1._" VI'-U';;J, rIle L·UII..a.t
ORDS Setup Steps
Select the Oracle REST Data Services file (ords.war) that you will use for the installation.
® Use Oracle REST Data Services that is included with SQL Developer
o Use Oracle REST Data Services that is at location:
ORDS File ...
Configuration Files Location Specify the location for your Orade REST Data Services configuration files.
Location: I/Users/john/ordsNoborders I Browse ...
Reset configuration files location using value from ords.war file Reset
l' Database Conne
1'-' l' PL/SQL Gateway l' APEX RESTful Se f Migrate APEX RE l' Run Standalone ~t ORDS Users
Install Summary
ORDS Version ORDS war file version is 3.0.3.351.13.24
Copyright © 2018, King Training Resources, LLC 32 http://www.kingtraining.com
ORDS Installed • After several wizard-based steps installation is complete
ORDS Installation Wizard - Step 6 of 6
Summary
l' ORDS Fih~ locati l' Database Conne l' PLlSQl Gateway l' APEX RESTfu I Se
Run Standalone Install Summa
Copyright © 2018, King Training Resources, LLC
. ORDS Installation Summary $"'~ ORDS War File
I f·····1ED File Name: / Applications/SQlDeveloper413 .app/Contents/Reso ! L .... ~ Version: 3.0.3.351.13.24 f·····~ Configuration location: /Usersljohn/ordsNoborders 8···[7 Database Connection
f·····~ Host: loralhost t·····1illli Po rt: 15 2 1 f·····1ED Service N a me: 0 rd t·····1ED Pl/SQl Gateway User: APEX_PUBLIC_USER L····IED Orade REST Data Services Schema Version: 3.0.5.124.10.54
.... ~. Run in Standalone Mode when installation completes
33 http://www.kingtraining.com
ORDS Administration • SOL Developer provides an Administration capability for ORDS
Navigate Run Source Team Tools Windo\l
Data Modeler ..
~ Bookmarks i}:I€K 11= Breakpoints 'fiB Cart ~ Change Management Ii Components
Connections DBA Data Miner
~ Dbms Output
Debugger Extension Diagnostics Files
• Find DB Object ~Log
Map View l'fI Migration Projects
OLAP II!) OWA Output ~ Processes ~ Properties
ResultCache l.sql
on times 4 M FLUSH BU M FLUSH SH on .on times 4i ter
.. ral * 42;
..... :1€1 , __ , ":...J __ •• _
. ~ Development
Copyright © 2018, King Training Resources, LLC 34 http://www.kingtraining.com
ORDS Reporting --
• SOL Developer has reporting built-in Reports. x I GJ 8"'8 Data Dictionary Reports
~"'0 About Your Database ~"'0 All Objects ~"'0 Application Express ~"'8 ASH and AWR ~"'0 Database Administration ~"'8 Data Di rti 0 nary ~ ... ~ Oracle REST Data Services l , ..... & IREST En abled Objects
~1) Object 11) Alias l~EMP' eao 2 JOHN INVI'SIBLE TEST Lnv i.s ib Le
Copyright © 2018, King Training Resources, LLC 35 http://www.kingtraining.com
Enable ORDS for Table • Right-click on a table to enable ORDS using a wizard based process
Func Que
... ®j Que
Import Data ... Export ...
Table Column Constraint Index Pri~ileges .s. tati sti cs Storage Trigger Spatial Red~(tion
:>
Enable REST Service ...
Copyright © 2018, King Training Resources, LLC
RESTful Services
RESTful Summary
Specify Details I'u) RESTful Summa
36
Summary SQL RESTful Services Summary
s···L27 Object RESTful Summary Enabled
f·····1mJi Alias: invisible test f·····~ Authorization ~equired L .... tt;tf Com m it
http://www.kingtraining.com
ManualORDS • Use SQL Developer wizards to map ORDS for SQL and PL/SQL rESTD~v~'opm~nt
[91
Data Modeler
Navigate Run Source Team Tools Windo'
~ Bookmarks i}~K
It:: Breakpoints ..... ~R ~ith_test_12c.Sql ----Yl 'f!!fJ Cart
~ ~ " ~ ~ I O.O~ $ Change Management lIS Components ..... ~p
I Connections :no, round (a, DBA Data Miner !III-
~ Dbms Output deptno -o:tg • 1; Debugger !III-
Extension Diagnostics Files Find DB Object
~Log ..... ~L I Map View
~ Migration Projects OLAP
IrQ OWA Output ~ Processes ~ Properties ..... ~I
.,",. Specify Module
till] REST Data Services $"'~ Modules
I 8··· I !±J .... ffi···~ Privileges
RESTful Services Wizard - Step 1 of 4
RESTful Summar
REST Data Services !III- iHIi Development
Copyright © 2018, King Training Resources, LLC 37
Module Name: I~d_ep~t_s_u_m_m _
Universal Resource Identifier
URI Prefix: ds ~-------------- Example: http://myhost:BOBO/apex/workspace/ds
~IPublish - Make this RESTful Service available for use
Pagination ~ize: 125 &3
[~ )( [origins Allowed
http://www.kingtraining.com
PL/SQL ORDS APls • Oracle provides a PL/SQL package that allows creation and manipulation of ORDS in code
• Complete PL/SQL API for defining and configuring RESTful services - May be put into scripts - May be repeated
https://docs.oracle.com/cd/ E56351 01/doc.30/e56293/ --- ords ref.htm#AELIG90180 ---
Copyright © 2018, King Training Resources, LLC 38 http://www.kingtraining.com
PL/SQL API in Use begin
ords.create_service(
p_module_name => 'samples.employees',
p_base_path => '/samples/employees',
p_pattern => '.',
p_items_per_page => 5,
p_source => 'select * from hr.employees
order by employee_id');
commit;
end;
Copyright © 2018, King Training Resources, LLC 39 http://www.kingtraining.com
Security • Security is an important part of todays applications • ORDS provides a standardized mechanism for URis
- May tie into Oracle Identity Management via WebGate to access Single Sign On (SSO)
- May use OAuth2 (built-in)
Copyright © 2018, King Training Resources, LLC 40 http://www.kingtraining.com
View Table Contents • Use URL to view all table rows
C <D loca I host: 8080/0 rd s/hrrest/em pi oyees/
II 20161011124847 2 II http://localhost:8080/ords/hrrest/ernployees/ 3
6 7 8 9 10 11 12 13
... {
Uemployee_i.dll: 100, "Fi rst_na.mell: "Steven", "Lcs t.incme ": 11 Ki.ng11 , "emo i 111: nSKINGn) uphone_numberu: 1'1515.123 .. 45671,
ulhi. re_date": 111987-06-17T04: 00: 00Z1 , U job_ i. d II: nAD_PRES 11 ,
Copyright © 2018, King Training Resources, LLC 41 http://www.kingtraining.com
View Row Contents • Use URL to view Row contents
~ C CD localllost:8080/ords/hrrest/employeesJ200
1 j R}eload this page ~074 740 2 II http://locolhost:8080/ords/hrrest/employees/200 3 4 " { 5 II empl oyee ; i d ": 2001, 6 "first_name": "Jenrrif'er "; 7 "last_name!!: nWhalenn,
8 II ema i 111: 11 J WHAL EN II , 9 II phone_numbelr 1": II 515 .123 .4444 II , 10 II h i r1e_date ": n 1987 -09-17T04: 00: 00Z II , 11 "job.rid": JlAD_ASSrn, 12 "salary'": 4400, 13 "commission_pet": null, 14 "manager_id": 101, 15 "department_id": 10, 16" "l inks II: [ 17 "
Copyright © 2018, King Training Resources, LLC 42 http://www.kingtraining.com
ORDS Access from Code // Javascript var myxhr = new XMLHttpReque myxhr.onreadystatechange function() {
if (myxhr.readyState
var mvdata = II Java DefaultHttpClient httpClie new DefaultHttpClient(); HttpGet myGet = new
HttpGet("my.host/ords/hrre loyees/200");
HttpResponse response = -- ht // jquery
// Php <?php
$url - https://my.host/ord rest/employees/200'
$response = __ file_get_contents ($, // Android
// Python
import Json
import requests
urI = https://my.host/ords/ hrrest/employees/200'
response = DefaultHtt-~'~--~ L~~ requests.get(url)
new Defe / / Ruby getdata = require 'j: response. j son ()
require 'n4 print getdata
urI = 'my.host/ords/hrrest/empl oyees/200'
print getdata re
ontent(»»;
new HttpGet ("n loyees/20(
HttpRespor htt Clien~ response =
Bu $. getJSON ("my. host/ords; p Net: : HTTP. get_response (UR Bu s/200", function ( getdai BufferedRe I .parse (uz L) )
BufferedRe processData(getdatc getdata = new Inpt JSON.parse(response.body) }) ;
reg,t·,,"' .... g ... ~ .. _ ........... :I \ I .~ .... _ow
) ) ) ) ; http://www.kingtraining.com
4
Wrapping it all Up
• The Crown Jewels are safe! • We control access to our data by providing exactly what the developers need and want - Web Services available via RESTful APls - Data in and out in JSON as well as other data types
• ORDS helps enable your newest applications
Copyright © 2018, King Training Resources, LLC 44 http://www.kingtraining.com
Plan Now to Attend Training Days 2019! February 19 - 21
Westin Westminster Hotel Copyright © 2018, King Training Resources, LLC 45 http://www.kingtraining.com
COLLABORATE18 TECHNOLOGY AND APPLICATIONS FORUM FOR THE ORACLE COMMUNITY
There is ONE event that delivers the full spectrum of Oracle Applications and Technology education that you need to boost results all year long. Produced by three independent users groups, COLLABORATE 18: Technology and Applications Forum for the Oracle Community delivers:
• More than 1,200 sessions and panels sourced from the user community
• 14 revamped education tracks to make finding your most relevant education easier - cloud, on-premises or hybrid
• Breaking news from Oracle
Focused networking, including interest group (SIG) meetings, geographic networking and receptions
• An Exhibitor Showcase packed with products and solution providers who can help you solve your specific challenges
GET INVOLVED AS A PRESENTER, ATTENDEE OR EXHIBITOR!
ATTENDCOLLABORATE.COM
presented by: (IOU G ) OAUG' Quest
• Please Complete Session Evaluations n
Create RESTful Services using ORDS (Oracle Rest Data Services) To contact the author:
John King King Training Resources P. o. Box 1780 Scottsdale, AZ 85252 USA 1.800.252.0652 - 1.303.798.5727 Email: [email protected] Twitter: royaltwit
Copyright © 2018, King Training Resources, LLC 48
• •
Thanks for your attention!
http://www.kingtraining.com
• End
Copyright © 2018, King Training Resources, LLC 49 http://www.kingtraining.com