oracle rest data services
TRANSCRIPT
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Creating RESTful APIsWith Oracle Database REST Data Services
Chris MuirDevelopment Tools Product ManagementSeptember, 2015
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 2
Safe Harbor StatementThe following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 3
Program Agenda
REST & JSON Overview
Oracle REST Data Services Overview
Demonstration
1
2
3
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 5
REpresentational State Transfer (REST)
An architectural style to defining, publishing and consuming APIs and services on the internet using HTTP.
- Formal definition (Zzzzzz)
Zzzzzzz…
Think of REST as a high level protocol for exchanging data across HTTP in a computer & developer friendly way.
- Anonymous product manager
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 6
REpresentational State Transfer (REST)
API
Does describe how the internet works
But we mostly talk about it in terms of
"web services"
That is software "sharing data"
A contemporary replacement for
"SOAP"
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
SOAP
implebjectccessrotocol
<xmlHell/> <XML/>
REST
{ 'json':true }
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 8
Why should you care about REST web services?
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 9
Why does Oracle care about REST web services?
Over 60 groups now using it as a standard The standard is
driving faster adoption
Common integration
technology for Fusion Apps
Core technology for Oracle's cloud stack
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 10
Why should you care about REST web services?
Over 60 groups now using it as a standard The standard is
driving faster adoption
Common integration
technology for Fusion Apps
Core technology for Oracle's cloud stack
Defacto development solution for web/JS, mobile
etc
Huge uptake across vendors, open source,
IT industry
Common language for integration
solutions Available wherever the web is available
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 11
No Really?! Why should I care about REST?
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 12
No Really?! Why should I care about REST?
// Javascriptvar xhr = new XMLHttpRequest();xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {var data = xhr.responseText;
doSomething(data);}
}xhr.open('GET', 'https://myhost/myapp/orders/1001’, true);xhr.send(null);
// JavaDefaultHttpClient httpClient = new DefaultHttpClient();HttpGet getRequest = new HttpGet("https://myhost/myapp/orders/1001");HttpResponse response = httpClient.execute(getRequest);BufferedReader br = new BufferedReader( new InputStreamReader((response.getEntity().getContent())));
// jquery$.getJSON( "https://myhost/myapp/orders/1001", function( data ) { doSomething(data);});
// Php<?php $url = 'http://myhost/myapp/orders/1001'; $response = file_get_contents($url); $data = json_decode($response); var_dump($data); ?>
// Rubyrequire 'json'require 'net/http’url = 'http://whatever/service'response = Net::HTTP.get_response(URI.parse(url)) data = JSON.parse(response.body) print data
// Python import json import requests
url = 'http://myhost/myapp/orders/1001' response = requests.get(url) data = response.json() print data
// AndroidDefaultHttpClient httpClient = new DefaultHttpClient();HttpGet getRequest = new HttpGet("https://myhost/myapp/orders/1001");HttpResponse response = httpClient.execute(getRequest);BufferedReader br = new BufferedReader( new InputStreamReader((response.getEntity().getContent())));
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 13
Lorem ipsum amet sit HTTP,
resources adipiscing URLs. Nunc
My essay on REST web services
placerat ligula ut metus, eu
sagititis. HTTP verbs mauris ac
pretium ipsum, no lacus. Aenean
payloads diam, ac purus
sit ame. Status codes vulputae
metus. Curabitur hendrerit null
a media types dignissim morbi.
The end.
Exam Question 1
Describe the coreconcepts of RESTweb services.
Exam Question 2
Explain RESTweb services
using pictures.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
http://cloud.oracle.com/mobile/index.html
Understanding REST: You are already an expert
Everyday you use a browser
And you enter URLs to "GET" a
"resource"
A URL is comprised of a remote server
A pathAnd a web page
"resource" of a specific "media type"
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
http://cloud.oracle.com/mobile/index.html
It's not a human accessing the resource, it's
software
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
http://cloud.oracle.com/mobile/index.html
And their accessing a remote service
It doesn't have to be web pages, it can be any file (media type)
It's not a human accessing the resource, it's
software
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
http://cloud.oracle.com/mobile/index.html
HTTP Request
HTTP Response
And they utilize the HTTP protocol
The client makes a HTTP request The server responds
There can be many request-response
cycles
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
http://cloud.oracle.com/mobile/index.html
Request
Response
HTTP Request
The HTTP request carries a payload
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP Request
GET /mobile/index.html HTTP/1.1
Host: cloud.oracle.com
User-Agent: Mozilla/5.0 Chrome/3.6Accept: text/htmlAccept-Language: en-usAccept-Encoding: gzip,deflateAccept-Charset: utf-8Keep-Alive: 115Connection: keep-alive
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP Request
GET /mobile/index.html HTTP/1.1
Host: cloud.oracle.com
User-Agent: Mozilla/5.0 Chrome/3.6Accept: text/htmlAccept-Language: en-usAccept-Encoding: gzip,deflateAccept-Charset: utf-8Keep-Alive: 115Connection: keep-alive
HTTP
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP Request
GET /mobile/index.html HTTP/1.1
Host: cloud.oracle.com
User-Agent: Mozilla/5.0 Chrome/3.6Accept: text/htmlAccept-Language: en-usAccept-Encoding: gzip,deflateAccept-Charset: utf-8Keep-Alive: 115Connection: keep-alive
HTTP
HTTP Verb:GET/HEAD/PUT/POST/DELETE
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP Request
GET /mobile/index.html HTTP/1.1
Host: cloud.oracle.com
User-Agent: Mozilla/5.0 Chrome/3.6Accept: text/htmlAccept-Language: en-usAccept-Encoding: gzip,deflateAccept-Charset: utf-8Keep-Alive: 115Connection: keep-alive
HTTP
HTTP Verb:GET/HEAD/PUT/POST/DELETE
URI: Server
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP Request
GET /mobile/index.html HTTP/1.1
Host: cloud.oracle.com
User-Agent: Mozilla/5.0 Chrome/3.6Accept: text/htmlAccept-Language: en-usAccept-Encoding: gzip,deflateAccept-Charset: utf-8Keep-Alive: 115Connection: keep-alive
HTTP
HTTP Verb:GET/HEAD/PUT/POST/DELETE
URI: Server
URI: Path + Resource
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP Request
GET /mobile/index.html HTTP/1.1
Host: cloud.oracle.com
User-Agent: Mozilla/5.0 Chrome/3.6Accept: text/htmlAccept-Language: en-usAccept-Encoding: gzip,deflateAccept-Charset: utf-8Keep-Alive: 115Connection: keep-alive
HTTP
HTTP Verb:GET/HEAD/PUT/POST/DELETE
URI: Server
URI: Path + Resource
HTTP Headers
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP Request
GET /mobile/index.html HTTP/1.1
Host: cloud.oracle.com
User-Agent: Mozilla/5.0 Chrome/3.6Accept: text/htmlAccept-Language: en-usAccept-Encoding: gzip,deflateAccept-Charset: utf-8Keep-Alive: 115Connection: keep-alive
HTTP
HTTP Verb:GET/HEAD/PUT/POST/DELETE
URI: Server
URI: Path + Resource
HTTP Headers Accept
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
HTTP Request
GET /mobile/index.html HTTP/1.1
Host: cloud.oracle.com
User-Agent: Mozilla/5.0 Chrome/3.6Accept: text/htmlAccept-Language: en-usAccept-Encoding: gzip,deflateAccept-Charset: utf-8Keep-Alive: 115Connection: keep-alive
HTTP
HTTP Verb:GET/HEAD/PUT/POST/DELETE
URI: Server
URI: Path + Resource
HTTP Headers Accept
No body
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
http://cloud.oracle.com/mobile/index.html
Request
Response
HTTP Response
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
http://cloud.oracle.com/mobile/data.json
Request
Response
HTTP Response
HTTP/1.1 200 OK
Date: 26 Jan 2015 00:02:25 GMTServer: Apache/2.0.55 (Ubuntu)Connection: Keep-AliveEtag: "1a690fe-40df-f1645340"
<html> <head> <title>Oracle MCS</title> </head> ..etc..
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
http://cloud.oracle.com/mobile/data.json
Request
Response
HTTP Response
HTTP/1.1 200 OK
Date: 26 Jan 2015 00:02:25 GMTServer: Apache/2.0.55 (Ubuntu)Connection: Keep-AliveEtag: "1a690fe-40df-f1645340"
<html> <head> <title>Oracle MCS</title> </head> ..etc..
Status Code
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
http://cloud.oracle.com/mobile/data.json
Request
Response
HTTP Response
HTTP/1.1 200 OK
Date: 26 Jan 2015 00:02:25 GMTServer: Apache/2.0.55 (Ubuntu)Connection: Keep-AliveEtag: "1a690fe-40df-f1645340"
<html> <head> <title>Oracle MCS</title> </head> ..etc.. Payload
Status Code
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Understanding REST: The four slide introduction
• Resources• HTTP verbs• Status codes• Media types
http://host/path/departmentsGET
http://host/path/employeesGET
http://host/path/departments/hrGET
http://host/path/employees/101GET
http://host/path/departments/hr/employeesGET
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Understanding REST: The four slide introduction
• Resources• HTTP verbs• Status codes• Media types DELETE
PUT
HEAD
GET
POST
'Read' a resource
'Create' a resource
'Update or Create'
'Delete' a resource
'Read' resource headers
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Understanding REST: The four slide introduction
• Resources• HTTP verbs• Status codes• Media types
Informational
Success
Redirection
Client Error
Server Error
4xx
3xx
5xx
1xx
2xx
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Understanding REST: The four slide introduction
• Resources• HTTP verbs• Status codes• Media types
Payload type 'requested' by client– Via HTTP Parameter "accept"– Defines MIME types. e.g.
• application/json, application/xml, image/gif
{"departments: [ {"id":"MAN","name":"Manfacturing"}, {"id":"HR","name":"Human Resources"}, {"id":"FIN","name":"Finance"}, ...etc... ]}
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Understanding JSON: The three slide introduction
JSON is a standard using human-readable text to transmit data objects of attribute-value pairs. It is typically used in machine to machine communications and is a contemporary replacement for the older XML standard.
- Wikipedia
{ "firstName":"John", "lastName":"Smith", "isAlive":true, "age":25, "address": { "streetAddress":"21 2nd Street", "city":"New York", "state":"NY", "postalCode":"10021-3100" }, "phoneNumbers": [ {"type":"home", "number":"1234"}, {"type":"office","number":"4567"} ], "children":[], "spouse":null}
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
• Textual data payloads• Human readable• Supports validation & schemas• "Fat free" alternative to XML• Compact mobile friendly payloads• JavaScript has inbuilt support
Understanding JSON: The three slide introduction{ "firstName":"John", "lastName":"Smith", "isAlive":true, "age":25, "address": { "streetAddress":"21 2nd Street", "city":"New York", "state":"NY", "postalCode":"10021-3100" }, "phoneNumbers": [ {"type":"home", "number":"1234"}, {"type":"office","number":"4567"} ], "children":[], "spouse":null}
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
{ "firstName":"John", "lastName":"Smith", "isAlive":true, "age":25, "address": { "streetAddress":"21 2nd Street", "city":"New York", "state":"NY", "postalCode":"10021-3100" }, "phoneNumbers": [ {"type":"home", "number":"1234"}, {"type":"office","number":"4567"} ], "children":[], "spouse":null}
• Blocks delineated by ellipses• Key-value pairs, separated by colon
– Key with quotes– Strings & dates with quotes– Boolean, integers, null without quotes– Supports nesting of records– Supports arrays/collections– Empty array– Null values
• Elements are comma delimited
Understanding JSON: The three slide introduction
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 38
Why?Congratulations!
You're now a REST expert
I feel kind of… icky
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 39
Program Agenda
REST & JSON Overview
Oracle REST Data Services Overview
Demonstration
1
2
3
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 40
Provides external data access via HTTP For modern development frameworks REST is contemporary choice for
JavaScript (web), mobile, cloud solutions
Maps standard HTTP/S RESTful calls to SQL Declaratively returns results in JSON format Supports high number of end users
Oracle REST Data Services (ORDS)
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 41
Release HistoryVersion Date Description
1.0 2010 First release as Oracle APEX Listener with with support for OWA toolkit used by APEX
1.1 2011 First release with REST support for JSON, Microdata, CSV, Pagination. Also added FOP
2.0 2012 OAuth2 support, Integrated with APEX, Multi Database, SQL Developer integration
2.0.5 2013 Added PDB support
2.0.6 2014 Renamed to Oracle REST Data Services to emphasize REST commitment
2.0.8 2014 Added REST Filtering
3.0 2015 REST AutoTable, NoSQL, DB12 JSON, Bulk loading over REST,…
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Oracle DatabaseHTTP/S client
Oracle REST Data Services
Transform
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Oracle DatabaseHTTP/S client
Oracle REST Data Services
Transform
ORDS runs in any Java EE container: e.g. WLS, Tomcat,
Glassfish
HTTP/S
Enhanced version of the Oracle Java mod_plsql Apache
module
There’s also a standalone version for dev purposes
It comes by default with
Oracle DBaaS
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Oracle DatabaseHTTP/S client
Oracle REST Data Services
Transform
HTTP/S
https://myhost/myapp/sales/orders/1001
HTTP/S & URI
Module Template
Client makes a HTTP 'GET'
requestContext Root
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Oracle DatabaseHTTP/S client
Oracle REST Data Services
Transform
https://myhost/myapp/sales/orders/1001
HTTP/S & URI
Module Template
ORDS maps to "ORDERS" SQL
Context Root
Map and Bind
SELECT * FROM ORDERSWHERE ORDERNO = :b1
HTTP/S
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Oracle DatabaseHTTP/S client
Oracle REST Data Services
Transform
https://myhost/myapp/sales/orders/1001
HTTP/S & URI
Module Template
JDBC SQL Call
Context Root
SELECT * FROM ORDERSWHERE ORDERNO = :b1
SQLMap and BindHTTP/S
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Oracle DatabaseHTTP/S client
Oracle REST Data Services
Transform
https://myhost/myapp/sales/orders/1001
HTTP/S & URI
Module TemplateContext Root
SELECT * FROM ORDERSWHERE ORDERNO = :b1
SQLMap and Bind
Result Set
DB returnsresult set
HTTP/S
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Oracle DatabaseHTTP/S client
Oracle REST Data Services
Transform
https://myhost/myapp/sales/orders/1001
HTTP/S & URI
Module TemplateContext Root
SELECT * FROM ORDERSWHERE ORDERNO = :b1
SQLMap and Bind
Transform Result Set
{ "orderno": 1001, "name": "Scott King", "address": "500 Main street, Innovation CA", "items": [ { "itemno": 404, "quantity": 7, "status": "in process"}, { "itemno": 303, "quantity": 32, "status": "closed"} ] }
HTTP/S
Transform to JSON, CSV, Excel or
Binary
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Oracle DatabaseHTTP/S client
Oracle REST Data Services
Transform
https://myhost/myapp/sales/orders/1001
HTTP/S & URI
Module TemplateContext Root
SELECT * FROM ORDERSWHERE ORDERNO = :b1
SQLMap and Bind
{ "orderno": 1001, "name": "Scott King", "address": "500 Main street, Innovation CA", "items": [ { "itemno": 404, "quantity": 7, "status": "in process"}, { "itemno": 303, "quantity": 32, "status": "closed"} ] }
JSON
HTTP/S
Response to HTTP request
Transform Result Set
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Summary: Serving JSON results from the database
App developers call named URI over HTTP(S) to retrieve and update data
Oracle REST Data Services (ORDS) Developer defines URI<>SQL mapping/binding
Utilizes the data stored in standard relational tables and columns
Oracle Database
HTTP/S
HTTP/S client
Map and Bind SQL
Transform Result SetJSON
Oracle REST Data Services
Transform
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 51
Program Agenda
REST & JSON Overview
Oracle REST Data Services Overview
Demonstration
1
2
3
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 52
http://bit.ly/letstalkoracle001
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 54
Installing ORDS support in the Database
• Several routes:1. Scripts2. APEX3. SQL Developer
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 74
Enabling ORDS support in the Database
• Several routes:1. PL/SQL APIs2. APEX3. SQL Developer
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
• Add as ?q=<filter>• Ensure to escape the filter
• Operators– $eq,$gt,$lt,$lte,$gte,– $ne,$instr,$asof
• Logical – $and, $or
• Examples:
?q={ "qty": { "$gt": 20 } }?q={"$and": [{"price": {"$ne": 1.99}},{"price": {"$notnull": ""}}] ?q={"price": [{"$ne": 1.99}},{"$notnull": ""}] ?q={"$or": [{"qty": {"$lt": 20}},{"sale": {"$eq": "TRUE"}}] ?q={$asof: {"$timestamp": ”……"}}
Generic Filtering via URI Query Support
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 92
Configuring Modules & Templates
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 116
For you tounderstand
Common ITlanguage
Unlock yourIT silos
Unlock yourdata
Data is akey asset
Drive the business
Consider theAPI world
ConsiderMicroservices
Overall REST should be a key technology for:
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 117
JSON inside the db
PL/JSON, APEX_JSON..
REST & JSON out of the db
Node.js DB Driver, ORDS..
….#cough #cough and just about every middleware product #hint #hint.
Don't forget the alternatives:
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Learn More With Gordon Smith
118
http://bit.ly/letstalkoracle003