SlideShare una empresa de Scribd logo
1 de 52
Paco van der Linden
Lucas Jellema
Oracle OpenWorld 2016, San Francisco, 22 September 2016
Database-Centric APIs on the Cloud
Using PL/SQL and Node.js
Database-Centric
APIs
on the
Cloud
using
PL/SQL
and
Node.js
2
PL/SQL
APIs
3
Introducing APIs: definition
• API = Application Programmatic Interface
• An API is to computer programs what a User Interface is to human users:
the entry point to the exposed functionality of [complex] systems
– Understandable, Standards based, Functionally adequate as well as Non-
Functionally,…
The System
A Computer
Program
A Human
User UI
API
4
Introducing APIs: objective
• APIs are used to
– Provide access to specific organization’s IT assets
– To specific internal or external stakeholders
– In a controlled, well defined manner
– That is reliable (runtime) and efficient (design time) for consumers
• APIs allow
– Tight operational integration across logistical chains and business processes
– Exploitation of enterprise data resources
– Interaction through a variety of UIs on a plethora of devices for a multitude of [niche]
user groups
SCOTT
EMP/
DEPT
5
Introducing APIs:
today’s example
• Our company has a sophisticated HRM system
• We would like our business partners for payrolling, pensions and health
insurance to be able to integrate our data into their systems
– On our terms (non functionally) and their specifications (functionally)
• For internal usage, we are developing a mobile web app with advanced
employee insight
The
HRM
System
API
C
o
r
e
M
o
bi
le
B
2
B
6
API design decisions
• Standards:
– Where: URL endpoint
– How: HTTP(S)
– ‘command’ Language: REST over HTTP
– Data format JSON (sometimes XML, CSV)
• Thinking in Resources
– As perceived by API consumers – not necessarily the canonical data model of the
enterprise systems
– Note: resources are persisted, APIs are stateless (no memory across calls)
• … and operations on Resources
– Queries, Resource creation, update and removal
(through REST verbs PUT, POST,… and URL paths and Query parameters)
• Message patterns
– Synchronous request/response (bread and butter of HTTP)
– Also: subscribe and get published/pushed to
(e.g. WebSockets, Server Sent Events or callback REST API)
7
Non functional API aspects
• In addition to the functional specifications – APIs have to satisfy non-
functional requirements
– From both the Consumers as well as the Publishing party
• Areas of non-functional requirements include
– Security (authorization, encryption)
– Transaction management
– Response time
– Available (and Scalable)
– Data quality: Reliable and Fresh
– Clarity of API design
• Non-functional facilities
– Billing and quota management
– Usage analytics
8
API realization
How to get from zero to an API?
• Design resources (URL paths), operations and message formats (JSON)
– Using specification language (RAML, Swagger)
– Possibly using tool
• Document, catalog, publish API design
– Using Catalog/Repository tool
• Create mock implementation plus unit test and publish
• Start programming against the API (based on design & mock)
• Implement the API
• Publish the real API
– Possibly using a “gateway” that provides generic facilities (security, caching, load
balancing,…)
Client
Program
API
9
Our objective
Oracle
Database
API
http(s)
REST
JSON
10
The app we want to develop
SCOTT
EMP/
DEPT
The
HRM
System
API
M
o
bi
le
Insert screenshots
from app
The App will show Employees with
details about their Department and their
Staff.
It supports voting for a new PRESIDENT
(to replace KING).
It shows the current votes in this
presidential election – and when new
votes come in, the app refreshes.
11
Designing the API for our case
• Define Resources
– List of Employees
– Employee
– List of Votes in Presidential Election
– Vote [in Presidential Election]
• Design HTTP Verb (action) and URL path & parameters
– GET /employees
– GET /votes
– GET /employees/:id
– POST /employees/:id/vote
– SSE (Server Sent Events) /employees/updates
12
Designing the API for our case
• Choose Message Formats
– JSON, XML, CSV, …
• Design Message Structure for [actions on] Resources
– Lookout for data types (number) and formats (date, time)
13
Create Formal API
Specification
• Using API design formats
– Swagger, RAML, API Blueprint
• Using API design and publication tools
– Apiary, API Designer, AnyPoint API Platform, Apigee, ..
– Oracle API Platform Cloud Service
• From API Design – it seems a small step to API Management
14
Mock Implementation
• Create a Mock Implementation of the API
(for example using Node.js and static JSON data sets)
– To allow developers who consume the API to start developing
– To further and more explicitly specify the design of the API
– To allow for unit testing (with mock injection) of the API client applications
• Also create Postman Collections with API test calls & unit tests
– Or use any other REST API Client tool
http
Mock Node.js application
with static JSON files
15
Test Calling the Mock API
16
Development of the App can
start now …
17
Exposing Oracle Database
to the outside world
MyDB
PDB demos
SCOTT
TBL DEPT
PL/SQL
Package
http
18
Exposing Oracle Database
to the outside world
MyDB
PDB demos
SCOTT
TBL DEPT
Native DB
WebServices
dbms_epg
Embedded
PL/SQL Gateway
PL/SQL
Package
GlassFish /Tomcat
/WebLogic
ORDS
Node
applic
ation
oracledb
DB driver
WebLogic
SOA Suite &
DB Adapter
WebLogic
ADF BC
REST
Java SE/EE
WebLogic/Tomcat/JBoss
JAX-RS &
JDBC
UTL_HTTP
http requests
DBaaS
MyDB
demos
SCOTT
DEPT
Application Container
Cloud
ICS
SOA CS
JCS
Oracle Cloud
REST APIs
on top of DBaaS
DBaaS
MyJCSDB
demos
SCOTT
DEPT
ICS Agent
ORDS
API
Application Container
Cloud
ICS
SOA CS
Connection
Integration
Request Mapping
Response Mapping
Connection
JCS
Connection
Connection
Connection
Connection
SCA
Composite
data-api
REST
API
oracledb
DB driver
Java EE App
REST API
(JAX-RS)
JDBC
Database
Adapter
REST APIs
on top of DBaaS
dbms_epg
utl_http
21
Add to the cloud mix
some non functional facilities
• API Platform CS
– for Governance and Management of APIs
• MCS
– exposing APIs specifically for mobile consumption offering mobile facilities such as
analytics, security, enrichment, push notification
– also MAX & MAF for mobile app development
• Identity CS
– identity management and authentication services
• Management Cloud
– IT and Log analytics for real time
monitoring and diagnostics
Identity
CS
DBaaSApplication
Container
Cloud
ICS
SOA CS
JCS
MCS
API[P]
CS
Management
CS
22
The implementation of choice
for today
Application Container
Cloud
Docker
Node.js Container
data-api
REST
API
DBaaS
oracledb
DB driver
MyDB
demos
SCOTT
23
Introducing Node.js
• Node.js is a platform for running [server side]
JavaScript applications
– Asynchronous, event driven and highly scalable
– Great for handling HTTP interactions
– Can be used as very light weight web/application server
– Runs on all major operating systems, easy to install, quick to run
• JavaScript is a popular, rapidly evolving programming language
– Very good at processing and producing JSON payloads
• Enormous community support
– For JavaScript in general and Node.js in particular – there is a large number of
frameworks and libraries for many different tasks
– NPM – node package manager – is tool for installing modules from a large repository
of reusable libraries
24
Mock api impl in Node.js
• Serve static resources
• Handle http requests
• Return mock responses
– Based on static files
http
Mock Node.js application
with static JSON files
Sources in GitHub:
https://github.com/pavadeli/oowsession2016
25
NPM Package:
node-oracledb database driver
• The node-oracledb driver connects to Oracle Database
for fast and functional applications.
– Similar for Node.js to what JDBC is for Java applications
• It is an open source project with Apache 2.0 license.
• It is maintained as an NPM package by Oracle and is under active
development.
• https://github.com/oracle/node-oracledb or
npm install node-oracledb
• Support for SQL and PL/SQL, Transaction Management, CLOBs and
BLOBs, Ref Cursors, authentication, H/A features …
– Leveraging OCI Oracle (Fat)
Client Libraries
26
Connect to Oracle Database
from node application …
var oracledb = require('oracledb');
oracledb.getConnection( {
user : "SCOTT",
password : "TIGER",
connectString : "somehost:1521/orcl",
})
.then( function(connection) {
return connection.execute(
"SELECT deptno, dname, loc " +
"FROM dept " +
"WHERE deptno = :deptno"
, { deptno: { val: 30, dir: oracledb.BIND_IN
, type: oracledb.NUMBER }
}
)
.then( function(result) {
console.log(result.rows);
return conn.close();
})
.catch(function(err) {
console.error(err);
return conn.close();
});
27
CORE API in Database
PL/SQL Package (& View)
• A Core API should be the access point for applications into the database
– Encapsulate tables
– Hide complex SQL
– Allow single round trip access to rich, nested data structures
– Inject authorization, logging, journaling, history, multi tenancy, caching, …
• Implementation: PL/SQL Package (and optionally a View)
SCOTT
TBL DEPT
PL/SQL Package
TBL EMP
View
IO
trg
28
CORE API:
Package EMPLOYEE_API
SCOTT
TBL DEPT
PL/SQL Package EMPLOYEE_API
TBL EMP
get_employees
return
employee_list_t
get_employee
(p_id in number) return
employee_t
Type employee_list_t
table of
employee_summary_t
Type
employee_summary_t
is Object of ()
Type employee_t
is Object of ()
Encapsulate:
authorization, history,
audit/log, cache, enrich,
translate, redact
29
User Defined Type
EMPLOYEE_T
30
API function:
get_employee
PL/SQL Package
EMPLOYEE_API
get_employee
(p_id in number) return
employee_t
31
API function:
get_employee (2/2)
PL/SQL Package
EMPLOYEE_API
get_employee
(p_id in number) return
employee_t
32
Interacting with Core API
SCOTT
TBL DEPT
PL/SQL Package EMPLOYEE_API
TBL EMP
get_employees
return
employee_list_t
get_employee
(p_id in number) return
employee_t
33
Interacting with Core API
SCOTT
TBL DEPT
PL/SQL Package EMPLOYEE_API
TBL EMP
get_employees
return
employee_list_t
get_employee
(p_id in number) return
employee_t
34
The node-oracledb driver does not
support user defined objects & collections
• The nested data structure cannot be transfered in the form of an object
[a user defined data type aka ADT or UDT]
• Long blocks of text
can be transfered
• If we can convert the
data structure into
tekst – we are in
business
• Two obvious text based
formats are available
for complex, nested data structures:
– XML
– JSON
• Node.js has a strong preference for JSON
PL/SQL Package EMPLOYEE_API
get_employees
return
employee_list_t
get_employee
(p_id in number) return
employee_t
?
35
Converting complex ADT to
XML and/or JSON
• Turning Objects and Collections into XML (and back) is
natively supported in Oracle Database
– using XMLType(user defined object).getstringval()
to produce VARCHAR2 (or CLOB) with XML based on ADT
– XMLType(XML string).toObject(user defined target object variable)
to create an ADT from a text block in [the proper] XML format
• Converting between ADT and JSON or between JSON and XML is not
natively supported (up to 12cR1)
– The open source PL/JSON library can be leveraged
– To get JSON for user defined object (via XML):
JSON_XML.xmlstr2json(XMLType(user defined object).getstringval())
– To go from a JSON document to an ADT (via XML):
X (XmlType):= json_xml.json_to_xml( json string, ’TARGET_T’);
Xmltype(replace(x.getClobVal(),chr(38)||’quot;’,’’))
.toobject(l_adt);
ADT/UDT Types
OBJECTS, NESTED
TABLE
XMLType
36
JSON support in user defined types
and API wrapper
• An API Wrapper is introduced to expose operations in terms of JSON
structures instead of ADTs
– The Node.js application only interacts
with this API
• Each user defined
object has a to_json()
member function
– Return varchar2 with
JSON representation of
complex data structure
• For large data structures
– CLOB can be used
– Alternatively:
select text
from table( get_emps_as_json)
• with get_emps_as_json return a collection
table of varchar2
PL/SQL Package EMPLOYEE_API
get_employees
return
employee_list_t
get_employee
(p_id in number) return
employee_t
?
PL/SQL Package
EMPLOYEE_JSON_API
get_employees_json
return varchar2
get_employee_json
(p_id in number)
return varchar2
Type employee_t is
Object of ()
to_json() return
varchar2
Type employee_summary_t is Object of ()
to_json() return varchar2
static function
to_json_employee_summary_list
( p_emp_list in employee_list_t)
37
to_json member function for
user defined type employee_t
Type employee_t is
Object of ()
to_json() return
varchar2
38
The Database API is done…
• Time to replace the mock implementation in the Node.js application
PL/SQL Package EMPLOYEE_API
get_employees
return
employee_list_t
get_employee
(p_id in number) return
employee_t
?
PL/SQL Package
EMPLOYEE_JSON_API
get_employees_json
return varchar2
get_employee_json
(p_id in number)
return varchar2
Type employee_t is Object of ()
to_json() return varchar2
Type employee_summary_t is Object of
()
to_json() return varchar2
static function
to_json_employee_summary_list
( p_emp_list in employee_list_t)
39
Implement the API in Node.js –
call out to PL/SQL API
1
2
3
4
expresshttp
5
6
7
40
Application Container Cloud
• Oracle Application Container Cloud [Service] aka ACCS
– Docker Container configured for Java SE or Node.js – can run a single application
Application Container Cloud
Docker
Node.js
Container
Node.js
Application
Archive
Docker
Java SE
Container
Web
App
41
Connect to DBaaS using node-
oracledb driver & service binding
Application Container
Cloud
Docker
Node.js Container
REST clients
data-api
REST
API
DBaaS
Service
Binding
oracledb
DB driver
MyJCSDB
demos PDB1
HR
42
Application Container Cloud
43
Demo of the API in action
expresshttp
https://data-api-lucasjellema.apaas.em2.oraclecloud.com/employee-api/employees/7782
http://tinyurl.com/hzdf5ta
PL/SQL Package
EMPLOYEE_JSON_API
44
Demo of the App on top of the API
http://tinyurl.com/h87fphz
PL/SQL Package
EMPLOYEE_JSON_API
45
Push Notifications
• Events in the HRM system
– triggered from any one of the many client devices or from a different channel or
background process
• May need to be pushed to the API consumer
– So the UI can be refreshed at once
• Potentially many consumers are involved
SCOTT
EMP/
DEPT
The
HRM
System
API
C
o
r
e
M
o
bi
le
46
The event is a vote
An update of the standings is desired
Table
presidential_
election
47
Implementing
Push Notifications
Push from Node.js to
consumers using:
- WebSocket
- Server Sent Events (SSE)
- - Native device push
Push from Database to Node.js using:
- HTTP call through UTL_HTTP
- Polling (in Node.js) on ‘events’ table
- UTL_TCP, Stored Java, …
48
Inside Out option: Database to Node.js
push using UTL_HTTP for call out
Table
presidential_
election
PL/SQL Package
EMPLOYEE_EVENT_HANDLER
utl_http
Insert Trigger on
each row
Use dbms_job to make
http call on commit
HTTP POST to
/employees-api/events
Send JSON message to all
SSE clients
49
Alternative: Database to Node.js push
using polling from Node.js
Table
presidential_
election
PL/SQL Package
EMPLOYEE_EVENT_HANDLER
Insert Trigger on
each row
Use dbms_job to insert
event on commit
Send JSON message to all
SSE clients
Table EVENTS_TO_PUSH
event_type
event_payload
timestamp
version
Scheduled
Event Polling
Retrieve events newer than
any previously fetched
For each new event:
based on type determine
what to do [with payload]
Create event record with
payload & timestamp
50
Push demo
The
HRM
System
51
Summary
• APIs are the foundation for tight operational B2B integration, data
exploitation and agile UI/UX implementation
• API design (documentation, mocking, testing) comes first
– Geared towards API usage (outside in approach)
• Oracle Databases hold valuable enterprise data collections
– that APIs can make very good use of
• Exposing database resources through APIs can easily be done
– With a Core PL/SQL API – encapsulating the database resources
– That is leveraged from Node.js to handle HTTP and transform JSON
• Node.js is great technology for implementing REST APIs
– Node.js applications can leverage node-oracledb driver to invoke PL/SQL
– Node.js applications can run on Oracle Application Container Cloud Service
– Node.js can help implement advanced mechanisms for
security, enrichment, push [SSE, WebSockets] and more
API
Blog: http://technology.amis.nl
Twitter: lucasjellema,
Mail: lucasjellema@gmail.com
Twitter: pavadeli
Mail: pavadeli@gmail.com

Más contenido relacionado

Destacado

Systems on the edge - your stepping stones into Oracle Public PaaS Cloud - AM...
Systems on the edge - your stepping stones into Oracle Public PaaS Cloud - AM...Systems on the edge - your stepping stones into Oracle Public PaaS Cloud - AM...
Systems on the edge - your stepping stones into Oracle Public PaaS Cloud - AM...
Lucas Jellema
 
Introducing Kafka's Streams API
Introducing Kafka's Streams APIIntroducing Kafka's Streams API
Introducing Kafka's Streams API
confluent
 
HMC_Industry_Report_Drone_Technology_160321[1]
HMC_Industry_Report_Drone_Technology_160321[1]HMC_Industry_Report_Drone_Technology_160321[1]
HMC_Industry_Report_Drone_Technology_160321[1]
Robert Cheek
 
Building Kafka-powered Activity Stream
Building Kafka-powered Activity StreamBuilding Kafka-powered Activity Stream
Building Kafka-powered Activity Stream
Oleksiy Holubyev
 

Destacado (16)

Systems on the edge - your stepping stones into Oracle Public PaaS Cloud - AM...
Systems on the edge - your stepping stones into Oracle Public PaaS Cloud - AM...Systems on the edge - your stepping stones into Oracle Public PaaS Cloud - AM...
Systems on the edge - your stepping stones into Oracle Public PaaS Cloud - AM...
 
Oracle Database 12c - Introducing SQL Pattern Recognition through MATCH_RECOG...
Oracle Database 12c - Introducing SQL Pattern Recognition through MATCH_RECOG...Oracle Database 12c - Introducing SQL Pattern Recognition through MATCH_RECOG...
Oracle Database 12c - Introducing SQL Pattern Recognition through MATCH_RECOG...
 
Oracle Management Cloud - introduction, overview and getting started (AMIS, 2...
Oracle Management Cloud - introduction, overview and getting started (AMIS, 2...Oracle Management Cloud - introduction, overview and getting started (AMIS, 2...
Oracle Management Cloud - introduction, overview and getting started (AMIS, 2...
 
Introducing Kafka's Streams API
Introducing Kafka's Streams APIIntroducing Kafka's Streams API
Introducing Kafka's Streams API
 
Row Pattern Matching 12c MATCH_RECOGNIZE OOW14
Row Pattern Matching 12c MATCH_RECOGNIZE OOW14Row Pattern Matching 12c MATCH_RECOGNIZE OOW14
Row Pattern Matching 12c MATCH_RECOGNIZE OOW14
 
Review Oracle OpenWorld 2015 - Overview, Main themes, Announcements and Future
Review Oracle OpenWorld 2015 - Overview, Main themes, Announcements and FutureReview Oracle OpenWorld 2015 - Overview, Main themes, Announcements and Future
Review Oracle OpenWorld 2015 - Overview, Main themes, Announcements and Future
 
The True State of the Oracle Public Cloud - Dutch Oracle Architects Platform ...
The True State of the Oracle Public Cloud - Dutch Oracle Architects Platform ...The True State of the Oracle Public Cloud - Dutch Oracle Architects Platform ...
The True State of the Oracle Public Cloud - Dutch Oracle Architects Platform ...
 
HMC_Industry_Report_Drone_Technology_160321[1]
HMC_Industry_Report_Drone_Technology_160321[1]HMC_Industry_Report_Drone_Technology_160321[1]
HMC_Industry_Report_Drone_Technology_160321[1]
 
Introducing Oracle Real-Time Integration Business Insight
Introducing Oracle Real-Time Integration Business InsightIntroducing Oracle Real-Time Integration Business Insight
Introducing Oracle Real-Time Integration Business Insight
 
Building Kafka-powered Activity Stream
Building Kafka-powered Activity StreamBuilding Kafka-powered Activity Stream
Building Kafka-powered Activity Stream
 
AgensGraph: a Multi-model Graph Database based on PostgreSql
AgensGraph: a Multi-model Graph Database based on PostgreSqlAgensGraph: a Multi-model Graph Database based on PostgreSql
AgensGraph: a Multi-model Graph Database based on PostgreSql
 
Comparison of Open Source Frameworks for Integrating the Internet of Things
Comparison of Open Source Frameworks for Integrating the Internet of ThingsComparison of Open Source Frameworks for Integrating the Internet of Things
Comparison of Open Source Frameworks for Integrating the Internet of Things
 
Comparing 30 MongoDB operations with Oracle SQL statements
Comparing 30 MongoDB operations with Oracle SQL statementsComparing 30 MongoDB operations with Oracle SQL statements
Comparing 30 MongoDB operations with Oracle SQL statements
 
What to Expect for Big Data and Apache Spark in 2017
What to Expect for Big Data and Apache Spark in 2017 What to Expect for Big Data and Apache Spark in 2017
What to Expect for Big Data and Apache Spark in 2017
 
GlobalsDB: Its significance for Node.js Developers
GlobalsDB: Its significance for Node.js DevelopersGlobalsDB: Its significance for Node.js Developers
GlobalsDB: Its significance for Node.js Developers
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 

Más de Lucas Jellema

Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
Lucas Jellema
 
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
Lucas Jellema
 
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Lucas Jellema
 
Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...
Lucas Jellema
 
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
Lucas Jellema
 
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Lucas Jellema
 
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Lucas Jellema
 

Más de Lucas Jellema (20)

Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...Introduction to web application development with Vue (for absolute beginners)...
Introduction to web application development with Vue (for absolute beginners)...
 
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
Making the Shift Left - Bringing Ops to Dev before bringing applications to p...
 
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
Lightweight coding in powerful Cloud Development Environments (DigitalXchange...
 
Apache Superset - open source data exploration and visualization (Conclusion ...
Apache Superset - open source data exploration and visualization (Conclusion ...Apache Superset - open source data exploration and visualization (Conclusion ...
Apache Superset - open source data exploration and visualization (Conclusion ...
 
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
CONNECTING THE REAL WORLD TO ENTERPRISE IT – HOW IoT DRIVES OUR ENERGY TRANSI...
 
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...Help me move away from Oracle - or not?!  (Oracle Community Tour EMEA - LVOUG...
Help me move away from Oracle - or not?! (Oracle Community Tour EMEA - LVOUG...
 
Op je vingers tellen... tot 1000!
Op je vingers tellen... tot 1000!Op je vingers tellen... tot 1000!
Op je vingers tellen... tot 1000!
 
IoT - from prototype to enterprise platform (DigitalXchange 2022)
IoT - from prototype to enterprise platform (DigitalXchange 2022)IoT - from prototype to enterprise platform (DigitalXchange 2022)
IoT - from prototype to enterprise platform (DigitalXchange 2022)
 
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
Who Wants to Become an IT Architect-A Look at the Bigger Picture - DigitalXch...
 
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
Steampipe - use SQL to retrieve data from cloud, platforms and files (Code Ca...
 
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
Automation of Software Engineering with OCI DevOps Build and Deployment Pipel...
 
Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...Introducing Dapr.io - the open source personal assistant to microservices and...
Introducing Dapr.io - the open source personal assistant to microservices and...
 
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
How and Why you can and should Participate in Open Source Projects (AMIS, Sof...
 
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
Microservices, Apache Kafka, Node, Dapr and more - Part Two (Fontys Hogeschoo...
 
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
Microservices, Node, Dapr and more - Part One (Fontys Hogeschool, Spring 2022)
 
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
6Reinventing Oracle Systems in a Cloudy World (RMOUG Trainingdays, February 2...
 
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
Help me move away from Oracle! (RMOUG Training Days 2022, February 2022)
 
Tech Talks 101 - DevOps (jan 2022)
Tech Talks 101 - DevOps (jan 2022)Tech Talks 101 - DevOps (jan 2022)
Tech Talks 101 - DevOps (jan 2022)
 
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
Conclusion Code Cafe - Microcks for Mocking and Testing Async APIs (January 2...
 
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...Cloud Native Application Development - build fast, low TCO, scalable & agile ...
Cloud Native Application Development - build fast, low TCO, scalable & agile ...
 

Último

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 

Último (20)

WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 

Oracle Database-Centric APIs on the Cloud Using PL/SQL and Node.js

  • 1. Paco van der Linden Lucas Jellema Oracle OpenWorld 2016, San Francisco, 22 September 2016 Database-Centric APIs on the Cloud Using PL/SQL and Node.js
  • 3. 3 Introducing APIs: definition • API = Application Programmatic Interface • An API is to computer programs what a User Interface is to human users: the entry point to the exposed functionality of [complex] systems – Understandable, Standards based, Functionally adequate as well as Non- Functionally,… The System A Computer Program A Human User UI API
  • 4. 4 Introducing APIs: objective • APIs are used to – Provide access to specific organization’s IT assets – To specific internal or external stakeholders – In a controlled, well defined manner – That is reliable (runtime) and efficient (design time) for consumers • APIs allow – Tight operational integration across logistical chains and business processes – Exploitation of enterprise data resources – Interaction through a variety of UIs on a plethora of devices for a multitude of [niche] user groups
  • 5. SCOTT EMP/ DEPT 5 Introducing APIs: today’s example • Our company has a sophisticated HRM system • We would like our business partners for payrolling, pensions and health insurance to be able to integrate our data into their systems – On our terms (non functionally) and their specifications (functionally) • For internal usage, we are developing a mobile web app with advanced employee insight The HRM System API C o r e M o bi le B 2 B
  • 6. 6 API design decisions • Standards: – Where: URL endpoint – How: HTTP(S) – ‘command’ Language: REST over HTTP – Data format JSON (sometimes XML, CSV) • Thinking in Resources – As perceived by API consumers – not necessarily the canonical data model of the enterprise systems – Note: resources are persisted, APIs are stateless (no memory across calls) • … and operations on Resources – Queries, Resource creation, update and removal (through REST verbs PUT, POST,… and URL paths and Query parameters) • Message patterns – Synchronous request/response (bread and butter of HTTP) – Also: subscribe and get published/pushed to (e.g. WebSockets, Server Sent Events or callback REST API)
  • 7. 7 Non functional API aspects • In addition to the functional specifications – APIs have to satisfy non- functional requirements – From both the Consumers as well as the Publishing party • Areas of non-functional requirements include – Security (authorization, encryption) – Transaction management – Response time – Available (and Scalable) – Data quality: Reliable and Fresh – Clarity of API design • Non-functional facilities – Billing and quota management – Usage analytics
  • 8. 8 API realization How to get from zero to an API? • Design resources (URL paths), operations and message formats (JSON) – Using specification language (RAML, Swagger) – Possibly using tool • Document, catalog, publish API design – Using Catalog/Repository tool • Create mock implementation plus unit test and publish • Start programming against the API (based on design & mock) • Implement the API • Publish the real API – Possibly using a “gateway” that provides generic facilities (security, caching, load balancing,…) Client Program API
  • 10. 10 The app we want to develop SCOTT EMP/ DEPT The HRM System API M o bi le Insert screenshots from app The App will show Employees with details about their Department and their Staff. It supports voting for a new PRESIDENT (to replace KING). It shows the current votes in this presidential election – and when new votes come in, the app refreshes.
  • 11. 11 Designing the API for our case • Define Resources – List of Employees – Employee – List of Votes in Presidential Election – Vote [in Presidential Election] • Design HTTP Verb (action) and URL path & parameters – GET /employees – GET /votes – GET /employees/:id – POST /employees/:id/vote – SSE (Server Sent Events) /employees/updates
  • 12. 12 Designing the API for our case • Choose Message Formats – JSON, XML, CSV, … • Design Message Structure for [actions on] Resources – Lookout for data types (number) and formats (date, time)
  • 13. 13 Create Formal API Specification • Using API design formats – Swagger, RAML, API Blueprint • Using API design and publication tools – Apiary, API Designer, AnyPoint API Platform, Apigee, .. – Oracle API Platform Cloud Service • From API Design – it seems a small step to API Management
  • 14. 14 Mock Implementation • Create a Mock Implementation of the API (for example using Node.js and static JSON data sets) – To allow developers who consume the API to start developing – To further and more explicitly specify the design of the API – To allow for unit testing (with mock injection) of the API client applications • Also create Postman Collections with API test calls & unit tests – Or use any other REST API Client tool http Mock Node.js application with static JSON files
  • 16. 16 Development of the App can start now …
  • 17. 17 Exposing Oracle Database to the outside world MyDB PDB demos SCOTT TBL DEPT PL/SQL Package http
  • 18. 18 Exposing Oracle Database to the outside world MyDB PDB demos SCOTT TBL DEPT Native DB WebServices dbms_epg Embedded PL/SQL Gateway PL/SQL Package GlassFish /Tomcat /WebLogic ORDS Node applic ation oracledb DB driver WebLogic SOA Suite & DB Adapter WebLogic ADF BC REST Java SE/EE WebLogic/Tomcat/JBoss JAX-RS & JDBC UTL_HTTP http requests
  • 20. DBaaS MyJCSDB demos SCOTT DEPT ICS Agent ORDS API Application Container Cloud ICS SOA CS Connection Integration Request Mapping Response Mapping Connection JCS Connection Connection Connection Connection SCA Composite data-api REST API oracledb DB driver Java EE App REST API (JAX-RS) JDBC Database Adapter REST APIs on top of DBaaS dbms_epg utl_http
  • 21. 21 Add to the cloud mix some non functional facilities • API Platform CS – for Governance and Management of APIs • MCS – exposing APIs specifically for mobile consumption offering mobile facilities such as analytics, security, enrichment, push notification – also MAX & MAF for mobile app development • Identity CS – identity management and authentication services • Management Cloud – IT and Log analytics for real time monitoring and diagnostics Identity CS DBaaSApplication Container Cloud ICS SOA CS JCS MCS API[P] CS Management CS
  • 22. 22 The implementation of choice for today Application Container Cloud Docker Node.js Container data-api REST API DBaaS oracledb DB driver MyDB demos SCOTT
  • 23. 23 Introducing Node.js • Node.js is a platform for running [server side] JavaScript applications – Asynchronous, event driven and highly scalable – Great for handling HTTP interactions – Can be used as very light weight web/application server – Runs on all major operating systems, easy to install, quick to run • JavaScript is a popular, rapidly evolving programming language – Very good at processing and producing JSON payloads • Enormous community support – For JavaScript in general and Node.js in particular – there is a large number of frameworks and libraries for many different tasks – NPM – node package manager – is tool for installing modules from a large repository of reusable libraries
  • 24. 24 Mock api impl in Node.js • Serve static resources • Handle http requests • Return mock responses – Based on static files http Mock Node.js application with static JSON files Sources in GitHub: https://github.com/pavadeli/oowsession2016
  • 25. 25 NPM Package: node-oracledb database driver • The node-oracledb driver connects to Oracle Database for fast and functional applications. – Similar for Node.js to what JDBC is for Java applications • It is an open source project with Apache 2.0 license. • It is maintained as an NPM package by Oracle and is under active development. • https://github.com/oracle/node-oracledb or npm install node-oracledb • Support for SQL and PL/SQL, Transaction Management, CLOBs and BLOBs, Ref Cursors, authentication, H/A features … – Leveraging OCI Oracle (Fat) Client Libraries
  • 26. 26 Connect to Oracle Database from node application … var oracledb = require('oracledb'); oracledb.getConnection( { user : "SCOTT", password : "TIGER", connectString : "somehost:1521/orcl", }) .then( function(connection) { return connection.execute( "SELECT deptno, dname, loc " + "FROM dept " + "WHERE deptno = :deptno" , { deptno: { val: 30, dir: oracledb.BIND_IN , type: oracledb.NUMBER } } ) .then( function(result) { console.log(result.rows); return conn.close(); }) .catch(function(err) { console.error(err); return conn.close(); });
  • 27. 27 CORE API in Database PL/SQL Package (& View) • A Core API should be the access point for applications into the database – Encapsulate tables – Hide complex SQL – Allow single round trip access to rich, nested data structures – Inject authorization, logging, journaling, history, multi tenancy, caching, … • Implementation: PL/SQL Package (and optionally a View) SCOTT TBL DEPT PL/SQL Package TBL EMP View IO trg
  • 28. 28 CORE API: Package EMPLOYEE_API SCOTT TBL DEPT PL/SQL Package EMPLOYEE_API TBL EMP get_employees return employee_list_t get_employee (p_id in number) return employee_t Type employee_list_t table of employee_summary_t Type employee_summary_t is Object of () Type employee_t is Object of () Encapsulate: authorization, history, audit/log, cache, enrich, translate, redact
  • 31. 31 API function: get_employee (2/2) PL/SQL Package EMPLOYEE_API get_employee (p_id in number) return employee_t
  • 32. 32 Interacting with Core API SCOTT TBL DEPT PL/SQL Package EMPLOYEE_API TBL EMP get_employees return employee_list_t get_employee (p_id in number) return employee_t
  • 33. 33 Interacting with Core API SCOTT TBL DEPT PL/SQL Package EMPLOYEE_API TBL EMP get_employees return employee_list_t get_employee (p_id in number) return employee_t
  • 34. 34 The node-oracledb driver does not support user defined objects & collections • The nested data structure cannot be transfered in the form of an object [a user defined data type aka ADT or UDT] • Long blocks of text can be transfered • If we can convert the data structure into tekst – we are in business • Two obvious text based formats are available for complex, nested data structures: – XML – JSON • Node.js has a strong preference for JSON PL/SQL Package EMPLOYEE_API get_employees return employee_list_t get_employee (p_id in number) return employee_t ?
  • 35. 35 Converting complex ADT to XML and/or JSON • Turning Objects and Collections into XML (and back) is natively supported in Oracle Database – using XMLType(user defined object).getstringval() to produce VARCHAR2 (or CLOB) with XML based on ADT – XMLType(XML string).toObject(user defined target object variable) to create an ADT from a text block in [the proper] XML format • Converting between ADT and JSON or between JSON and XML is not natively supported (up to 12cR1) – The open source PL/JSON library can be leveraged – To get JSON for user defined object (via XML): JSON_XML.xmlstr2json(XMLType(user defined object).getstringval()) – To go from a JSON document to an ADT (via XML): X (XmlType):= json_xml.json_to_xml( json string, ’TARGET_T’); Xmltype(replace(x.getClobVal(),chr(38)||’quot;’,’’)) .toobject(l_adt); ADT/UDT Types OBJECTS, NESTED TABLE XMLType
  • 36. 36 JSON support in user defined types and API wrapper • An API Wrapper is introduced to expose operations in terms of JSON structures instead of ADTs – The Node.js application only interacts with this API • Each user defined object has a to_json() member function – Return varchar2 with JSON representation of complex data structure • For large data structures – CLOB can be used – Alternatively: select text from table( get_emps_as_json) • with get_emps_as_json return a collection table of varchar2 PL/SQL Package EMPLOYEE_API get_employees return employee_list_t get_employee (p_id in number) return employee_t ? PL/SQL Package EMPLOYEE_JSON_API get_employees_json return varchar2 get_employee_json (p_id in number) return varchar2 Type employee_t is Object of () to_json() return varchar2 Type employee_summary_t is Object of () to_json() return varchar2 static function to_json_employee_summary_list ( p_emp_list in employee_list_t)
  • 37. 37 to_json member function for user defined type employee_t Type employee_t is Object of () to_json() return varchar2
  • 38. 38 The Database API is done… • Time to replace the mock implementation in the Node.js application PL/SQL Package EMPLOYEE_API get_employees return employee_list_t get_employee (p_id in number) return employee_t ? PL/SQL Package EMPLOYEE_JSON_API get_employees_json return varchar2 get_employee_json (p_id in number) return varchar2 Type employee_t is Object of () to_json() return varchar2 Type employee_summary_t is Object of () to_json() return varchar2 static function to_json_employee_summary_list ( p_emp_list in employee_list_t)
  • 39. 39 Implement the API in Node.js – call out to PL/SQL API 1 2 3 4 expresshttp 5 6 7
  • 40. 40 Application Container Cloud • Oracle Application Container Cloud [Service] aka ACCS – Docker Container configured for Java SE or Node.js – can run a single application Application Container Cloud Docker Node.js Container Node.js Application Archive Docker Java SE Container Web App
  • 41. 41 Connect to DBaaS using node- oracledb driver & service binding Application Container Cloud Docker Node.js Container REST clients data-api REST API DBaaS Service Binding oracledb DB driver MyJCSDB demos PDB1 HR
  • 43. 43 Demo of the API in action expresshttp https://data-api-lucasjellema.apaas.em2.oraclecloud.com/employee-api/employees/7782 http://tinyurl.com/hzdf5ta PL/SQL Package EMPLOYEE_JSON_API
  • 44. 44 Demo of the App on top of the API http://tinyurl.com/h87fphz PL/SQL Package EMPLOYEE_JSON_API
  • 45. 45 Push Notifications • Events in the HRM system – triggered from any one of the many client devices or from a different channel or background process • May need to be pushed to the API consumer – So the UI can be refreshed at once • Potentially many consumers are involved SCOTT EMP/ DEPT The HRM System API C o r e M o bi le
  • 46. 46 The event is a vote An update of the standings is desired Table presidential_ election
  • 47. 47 Implementing Push Notifications Push from Node.js to consumers using: - WebSocket - Server Sent Events (SSE) - - Native device push Push from Database to Node.js using: - HTTP call through UTL_HTTP - Polling (in Node.js) on ‘events’ table - UTL_TCP, Stored Java, …
  • 48. 48 Inside Out option: Database to Node.js push using UTL_HTTP for call out Table presidential_ election PL/SQL Package EMPLOYEE_EVENT_HANDLER utl_http Insert Trigger on each row Use dbms_job to make http call on commit HTTP POST to /employees-api/events Send JSON message to all SSE clients
  • 49. 49 Alternative: Database to Node.js push using polling from Node.js Table presidential_ election PL/SQL Package EMPLOYEE_EVENT_HANDLER Insert Trigger on each row Use dbms_job to insert event on commit Send JSON message to all SSE clients Table EVENTS_TO_PUSH event_type event_payload timestamp version Scheduled Event Polling Retrieve events newer than any previously fetched For each new event: based on type determine what to do [with payload] Create event record with payload & timestamp
  • 51. 51 Summary • APIs are the foundation for tight operational B2B integration, data exploitation and agile UI/UX implementation • API design (documentation, mocking, testing) comes first – Geared towards API usage (outside in approach) • Oracle Databases hold valuable enterprise data collections – that APIs can make very good use of • Exposing database resources through APIs can easily be done – With a Core PL/SQL API – encapsulating the database resources – That is leveraged from Node.js to handle HTTP and transform JSON • Node.js is great technology for implementing REST APIs – Node.js applications can leverage node-oracledb driver to invoke PL/SQL – Node.js applications can run on Oracle Application Container Cloud Service – Node.js can help implement advanced mechanisms for security, enrichment, push [SSE, WebSockets] and more API
  • 52. Blog: http://technology.amis.nl Twitter: lucasjellema, Mail: lucasjellema@gmail.com Twitter: pavadeli Mail: pavadeli@gmail.com

Notas del editor

  1. Database-Centric APIs on the Cloud Using PL/SQL and Node.js  APIs are crucial in today's IT landscape. Enabling REST services to read and manipulate data in formats easily accessible by a wide range of consumers is a key objective. This session shows how Oracle Database can play a key role in offering such APIs. Using a combination of PL/SQL packages (using rich SQL, JavaScript Object Notation, and user-defined types) and a Node.js application with the Node Oracle Database driver, it's quite straightforward. This combination runs on-premises and just as easily on the Oracle's database-as-a-service and platform-as-a-service solutions. Demos illustrate the development and deployment on the cloud of such APIs. Expect some advanced SQL and PL/SQL and a quick introduction into Node.js. Conference Session Thursday, Sep 22, 9:30 a.m. - 10:15 a.m. | Park Central - Concordia
  2. https://github.com/oracle/node-oracledb http://www.oracle.com/technetwork/database/database-technologies/scripting-languages/node_js/index.html https://technology.amis.nl/2016/02/06/linking-application-container-cloud-to-dbaas-expose-rest-api-from-node-js-application-leveraging-node-oracle-database-driver/ https://oraclejetsample-lucasjellema.apaas.em2.oraclecloud.com/?root=hrm https://data-api-lucasjellema.apaas.em2.oraclecloud.com/departments https://artist-enricher-api-lucasjellema.apaas.em2.oraclecloud.com/artists/get?artist=meat+loaf
  3. From PL/SQL use UTL_HTTP to call out to API to pass message This article also describes this: https://jsao.io/2015/02/real-time-data-with-node-js-socket-io-and-oracle-database/ UTL_HTTP over SSL (to HTTPS) requires certificates to be uploaded into Oracle Wallet and wallet configured with UTL_HTTP