Contenu connexe Similaire à Oracle REST Data Services (20) Oracle REST Data Services1. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Creating RESTful APIs
With Oracle Database REST Data Services
Chris Muir
Development Tools Product Management
September, 2015
2. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The 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.
2
3. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Program Agenda
REST & JSON Overview
Oracle REST Data Services Overview
Demonstration
1
2
3
3
4. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 4
You tell me
What is REST?
5. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
REpresentational State Transfer (REST)
5
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
6. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
REpresentational State Transfer (REST)
6
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"
7. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
S
O
A
P
imple
bject
ccess
rotocol
<xmlHell/> <XML/>
REST
{ 'json':true }
8. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 8
Why should you care about REST web services?
9. 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
10. 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
11. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
No Really?! Why should I care about REST?
11
12. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
No Really?! Why should I care about REST?
12
// Javascript
var 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);
// Java
DefaultHttpClient 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);
?>
// Ruby
require '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
// Android
DefaultHttpClient 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())));
13. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 13
Exam Question 1
Describe the core
concepts of REST
web services.
Exam Question 2
Explain REST
web services
using pictures.
14. 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 path
And a web page
"resource" of a specific
"media type"
15. 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
16. 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
17. 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
18. 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
19. 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.6
Accept: text/html
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: utf-8
Keep-Alive: 115
Connection: keep-alive
20. 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.6
Accept: text/html
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: utf-8
Keep-Alive: 115
Connection: keep-alive
HTTP
21. 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.6
Accept: text/html
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: utf-8
Keep-Alive: 115
Connection: keep-alive
HTTP
HTTP Verb:
GET/HEAD/PUT
/POST/DELETE
22. 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.6
Accept: text/html
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: utf-8
Keep-Alive: 115
Connection: keep-alive
HTTP
HTTP Verb:
GET/HEAD/PUT
/POST/DELETE
URI: Server
23. 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.6
Accept: text/html
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: utf-8
Keep-Alive: 115
Connection: keep-alive
HTTP
HTTP Verb:
GET/HEAD/PUT
/POST/DELETE
URI: Server
URI: Path +
Resource
24. 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.6
Accept: text/html
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: utf-8
Keep-Alive: 115
Connection: keep-alive
HTTP
HTTP Verb:
GET/HEAD/PUT
/POST/DELETE
URI: Server
URI: Path +
Resource
HTTP
Headers
25. 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.6
Accept: text/html
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: utf-8
Keep-Alive: 115
Connection: keep-alive
HTTP
HTTP Verb:
GET/HEAD/PUT
/POST/DELETE
URI: Server
URI: Path +
Resource
HTTP
Headers
Accept
26. 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.6
Accept: text/html
Accept-Language: en-us
Accept-Encoding: gzip,deflate
Accept-Charset: utf-8
Keep-Alive: 115
Connection: keep-alive
HTTP
HTTP Verb:
GET/HEAD/PUT
/POST/DELETE
URI: Server
URI: Path +
Resource
HTTP
Headers
Accept
No body
27. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
http://cloud.oracle.com/mobile/index.html
Request
Response
HTTP Response
28. 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 GMT
Server: Apache/2.0.55 (Ubuntu)
Connection: Keep-Alive
Etag: "1a690fe-40df-f1645340"
<html>
<head>
<title>Oracle MCS</title>
</head>
..etc..
29. 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 GMT
Server: Apache/2.0.55 (Ubuntu)
Connection: Keep-Alive
Etag: "1a690fe-40df-f1645340"
<html>
<head>
<title>Oracle MCS</title>
</head>
..etc..
Status Code
30. 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 GMT
Server: Apache/2.0.55 (Ubuntu)
Connection: Keep-Alive
Etag: "1a690fe-40df-f1645340"
<html>
<head>
<title>Oracle MCS</title>
</head>
..etc.. Payload
Status Code
31. 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
32. 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
33. 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
34. 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...
]}
35. 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
}
36. 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
}
37. 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
38. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 38
Why?Congratulations!
You're now a
REST expert
I feel kind of… icky
39. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Program Agenda
REST & JSON Overview
Oracle REST Data Services Overview
Demonstration
1
2
3
39
40. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
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
40
Oracle REST Data Services (ORDS)
41. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 41
Release History
Version 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,…
42. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Oracle DatabaseHTTP/S client
Oracle REST Data Services
Transform
43. 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
44. 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'
request
Context Root
45. 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 ORDERS
WHERE ORDERNO = :b1
HTTP/S
46. 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 ORDERS
WHERE ORDERNO = :b1
SQLMap and BindHTTP/S
47. 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 ORDERS
WHERE ORDERNO = :b1
SQLMap and Bind
Result Set
DB returns
result set
HTTP/S
48. 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 ORDERS
WHERE 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
49. 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 ORDERS
WHERE 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
50. 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
51. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Program Agenda
REST & JSON Overview
Oracle REST Data Services Overview
Demonstration
1
2
3
51
52. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 52
http://bit.ly/letstalkoracle001
54. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Installing ORDS support in the Database
• Several routes:
1. Scripts
2. APEX
3. SQL Developer
54
74. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Enabling ORDS support in the Database
• Several routes:
1. PL/SQL APIs
2. APEX
3. SQL Developer
74
75. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Enabling AutoREST Support
75
91. 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
92. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Configuring Modules & Templates
92
116. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | 116
For you to
understand
Common IT
language
Unlock your
IT silos
Unlock your
data
Data is a
key asset
Drive the
business
Consider the
API world
Consider
Microservices
Overall REST should be a key technology for:
117. 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:
118. Copyright © 2015, Oracle and/or its affiliates. All rights reserved. |
Learn More With Gordon Smith
118
http://bit.ly/letstalkoracle003
Notes de l'éditeur This is a Safe Harbor Front slide, one of two Safe Harbor Statement slides included in this template.
One of the Safe Harbor slides must be used if your presentation covers material affected by Oracle’s Revenue Recognition Policy
To learn more about this policy, e-mail: Revrec-americasiebc_us@oracle.com
For internal communication, Safe Harbor Statements are not required. However, there is an applicable disclaimer (Exhibit E) that should be used, found in the Oracle Revenue Recognition Policy for Future Product Communications. Copy and paste this link into a web browser, to find out more information.
http://my.oracle.com/site/fin/gfo/GlobalProcesses/cnt452504.pdf
For all external communications such as press release, roadmaps, PowerPoint presentations, Safe Harbor Statements are required. You can refer to the link mentioned above to find out additional information/disclaimers required depending on your audience.