Oracle ORDS 101 - Jumpstart your Development · 1.0 2010 First release as Oracle APEX Listener with...

66
Oracle ORDS 101 - Jumpstart your Development Dietmar Aust Opal-Consul;ng, Köln www.opal-consul;ng.de

Transcript of Oracle ORDS 101 - Jumpstart your Development · 1.0 2010 First release as Oracle APEX Listener with...

Page 1: Oracle ORDS 101 - Jumpstart your Development · 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

OracleORDS101-JumpstartyourDevelopment

DietmarAustOpal-Consul;ng,Kölnwww.opal-consul;ng.de

Page 2: Oracle ORDS 101 - Jumpstart your Development · 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

► Dipl.-Inform.DietmarAust,FreelanceConsultant▪  Master'sDegreeinComputerScience(MSCS)

► BuildingOraclebasedWebApplica;onssince1997▪  Portal,Forms,Reports,OWAToolkit,nowAPEX!

► 1997-2000:ConsultantatOracleGermany

► Since09/2000:FreelanceConsultant,Since2006–APEXonly!

► Blog:h\p://daust.blogspot.com/

► RegularpresenteratOracleconferences(ODTUG,DOAG,OOW)

► AuthoroftheJasperReportsIntegra;ontoolkit▪  h\p://www.opal-consul;ng.de/tools

DietmarAust

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 2

Page 3: Oracle ORDS 101 - Jumpstart your Development · 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

DietmarAust

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 3

► 2015DatabaseDeveloperoftheyearintheORDScategory▪  PrimarilyformyknowledgeregardingORDSasthepla_ormtechnologyforAPEX▪  RESTfulServiceswithORDSares;llrela;velynew–buttheyhavegreatpoten;al

andwillgaininimportance

Page 4: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 4

Agenda

Page 5: Oracle ORDS 101 - Jumpstart your Development · 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

► WhatisREST?

► WhatisORDS?▪  ComponentsandArchitecture

► ManagementoftheRESTdefini;onswithSQLDeveloperandtheAPI

► UseCases▪  Naviga;on/Links/Filter/Sor;ng/Parameter(Input/Output)

► Security▪  Authen;ca;onandAuthoriza;on

► Addi;onalReading

► TheslidesandthedemoscriptwillbeavailablefromOGh.nlwebsiteandalsoonmyblog:h\p://daust.blogspot.de

Agenda

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 5

Page 6: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 6

WhatisREST?

Page 7: Oracle ORDS 101 - Jumpstart your Development · 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

► Itisanarchitecturalstyleforapplica;ons,neitheraprotocolnoraW3Cstandard

► REST:=Representa;onalStateTransfertermcoinedin2000byRoyFielding▪  h\ps://en.wikipedia.org/wiki/Representa;onal_state_transfer

► Characteris;cs:▪  Stateless(100%oftheapplica;onstateismanagedbytheclient)▪  Basedontheh\pprotocol▪  Highlyscaleable▪  RESTusesh\pmethods(POST,PUT,GET,DELETE,…)toimplementCRUD

opera;ons(Create/Read/Update/Delete)

► Why?▪  Lightweightalterna;vetoRPC(RemoteProcedureCalls)andotherWebServices

(SOAP,WSDL,…)▪  IncreasinglypopularthroughAPIsprovidedbyGoogle,Facebook,Twi\erand

others.

WhatisREST?Defini;on

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 7

Page 8: Oracle ORDS 101 - Jumpstart your Development · 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

► Ressourcesprovideservicesandareuniquelyiden;fyable▪  h\p://api.example.com/customers/▪  h\p://api.example.com/customers/1234▪  h\p://api.example.com/customers/1234/orders/

► Mul;pleURIscanpointtothesameressource:▪  h\p://example.org/NewOrleans/traffic/I10▪  h\p://example.org/traffic/NewOrleans/I10

► Wemodeltheressource,nottheac;on!▪  Useofnounsinpluralform▪  PUTh\p://example.com/accounts/12345▪  PUTh\p://example.com/accounts/edit/12345▪  POSTh\p://example.com/accounts/▪  POSTh\p://example.com/accounts/addaccount

WhatisREST?Ressources

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 8

Page 9: Oracle ORDS 101 - Jumpstart your Development · 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

► Methodsimplementaspecificopera;on▪  Uniformopera;onsforallressources▪  GET,POST,PUT,DELETE,OPTIONS,HEAD

► Weuseveryfewverbstooperateonmanydifferentnouns.

WhatisREST?Methods

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 9

Page 10: Oracle ORDS 101 - Jumpstart your Development · 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

► Communica;onofsuccessanderrormessagesthroughstandardHTTPResponsecodes1xx,2xx,3xx,4xx,5xx▪  h\p://www.restapitutorial.com/

h\pstatuscodes.html#

WhatisREST?Methods

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 10

Page 11: Oracle ORDS 101 - Jumpstart your Development · 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

► Representa;onsdeterminehowtheanswerwillbeinterpreted▪  XMLrepresenta;onusingmime-type:text/xml▪  JSONrepresenta;onusingmime-type:

applica;on/json

► Asingleressourcecanprovidemul;pledifferentrepresenta;ons▪  JSON,XML,CSV…▪  Therightrepresenta;onisac;vely„nego;ated“▪  Theclientsendsalistofpreferredmime-types–

theserverrespondswiththebestanswerandsendsthechosenmime-typeinthe„Content-Type“h\pheader.

WhatisREST?Representa;ons

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 11

Page 12: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 12

WhatisORDS?

Page 13: Oracle ORDS 101 - Jumpstart your Development · 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

► OracleRestDataServices(ORDS)▪  MiddlewareJ2EEcomponentinthe

applica;onserver(WLS,Glassfish,Tomcat)▪  TranslatesURLsintoacallinthedatabase

(eitherselectorstoredprocedurecall)

► Threemajorusecases▪  SupportforOWAtoolkitapplica;ons(will

replacemod_plsql)▪  OracleApplica;onExpress(APEX)▪  RESTfulWebservices

WhatisORDS?

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 13

Page 14: Oracle ORDS 101 - Jumpstart your Development · 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

WhatisORDS?TheHistory

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 14

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 support for Oracle Pluggable Databases (12c)

2.0.6 2014 Renamed to Oracle REST Data Services to emphasize REST commitment, integration with APEX 4.2 in SQL Workshop

2.0.8 2014 Added REST Filtering

3.0.0 2015 REST AutoTable, NoSQL, DB12 JSON, Bulk loading over REST,…

Page 15: Oracle ORDS 101 - Jumpstart your Development · 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

ORDSiscurrentlytransi2oningawayfromthedependencyonAPEX

► ORDSrequiresarepositorytostorethewebservicedefini;ons

WhatisORDS?APEXRESTvs.ORDS_METADATARESTSupport

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 15

► ORDS2.0

► Schemas▪  APEX_040200/APEX_050000▪  APEX_LISTENER▪  APEX_REST_PUBLIC_USER

► Configurationusing▪  APEXSQLWorkshop

► ORDS3.0

► Schemas▪  ORDS_METADATA▪  ORDS_PUBLIC_USER

► Configurationusing▪  SQLDeveloper▪  PL/SQLAPI

Page 16: Oracle ORDS 101 - Jumpstart your Development · 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

► APEXRESTsupportintheAPEXSQLWorkshop

WhatisORDS?APEXRESTvs.ORDS_METADATARESTSupport

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 16

Page 17: Oracle ORDS 101 - Jumpstart your Development · 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

► Twodifferentrepositories:APEXRESTandORDS_METADATAREST▪  TypicallybothareinstalledwhenusingAPEX5▪  APEX5requiresthatyourunapex_rest_config.sqlwhichcreatesAPEX_LISTENER

andAPEX_REST_PUBLIC_USER

► InwhichrepositorydoIcreatethewebservice?

► APEXREST▪  Integra;onwithAPEXSession

► ORDS_METADATAREST▪  ThenewRESTfunc;onalitybasedonthenewmetadatarepository▪  PL/SQLAPIs(defineandoauth)

► TheFuture?▪  NewfeatureswillonlybeaddedtoORDS_METADATAREST

WhatisORDS?APEXRESTvs.ORDS_METADATARESTSupport

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 17

Page 18: Oracle ORDS 101 - Jumpstart your Development · 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

► Currentlythedocumenta;ondoesn’talwaysclearlydis;nguishbetweenAPEXRESTandORDS_METADATAREST.

► Thusthesamplesinthedocumenta;onandontheinternetaremixed….buttherearesmallfunc;onaldifferences!

► Inthispresenta;onwewillfocusonthefeaturesavailableinORDS_METADATARESTSupportwithORDS3.0

WhatisORDS?APEXRESTvs.ORDS_METADATARESTSupport

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 18

Page 19: Oracle ORDS 101 - Jumpstart your Development · 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

► HowisaRESTwebservicecallactuallyprocessed?

WhatisORDS?Architecture

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 19

http://myhost/ords/employees/7536SELECT*FROMEMPWHEREEMPNO=:b1

Oracle DB

3. SQL Call over JDBC

Browser

1. Browser RESTful get request

2. ORDS maps to “EMPLOYEES” SQL

4. DB returns JDBC Results

5. JSON

ORDS Runs in WLS, Tomcat, Glassfish container

Oracle REST Data Services

Page 20: Oracle ORDS 101 - Jumpstart your Development · 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

► MapandBind:

▪  ImplicitlyaccessallURIparametersintheURLorinthebody(e.g.POSTrequest)−  Happensautoma;cally,evenJSONParameters(usingContent-Type:

applica;on/json)

▪  Explicitparameterspossible▪  Accessheadervariables

WhatisORDS?Architecture

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 20

Page 21: Oracle ORDS 101 - Jumpstart your Development · 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

► TransformtoJSON

▪  ReturnJSONbyusingbindvariables(declara;vely)orcreatetheJSONmanuallyyourself

▪  Declara;veFormats:JSONorCSV,manuallyyoucancreateanything▪  Canchangetheh\preturncodeorseth\pheadervariables

WhatisORDS?Architecture

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 21

Page 22: Oracle ORDS 101 - Jumpstart your Development · 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

► Connec;onPooling▪  ThetargetOracleuser(schema)isac;vatedusingaProxyConnect▪  TheuserORDS_PUBLIC_USERconnecttothedatabaseandthenswitchesitsiden;tyto

thetargetOracleuser▪  Thusweneedfewerconnec;onpoolsandeachconnec;onpoolbecomessmallersince

mul;pleOracleuserscanbeservedwiththesameconnec;onpool▪  EachSQLandPL/SQLstatementisexecutedusingthetheoriginalusersession

WhatisORDS?Architecture

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 22

Page 23: Oracle ORDS 101 - Jumpstart your Development · 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

► Connec;onPooling▪  EasiertodealwiththanwithAPEX,sincewithAPEXthesessionuserwillbe

APEX_PUBLIC_USER,NOTtheparsingschema

WhatisORDS?Architecture

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 23

Page 24: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 24

ManagementoftheRESTdefini;onswithSQLDeveloperandtheAPI

Page 25: Oracle ORDS 101 - Jumpstart your Development · 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

► ManagementoftheRESTdefini;onswithSQLDeveloper

RESTDefini;onsManagementwithSQLDeveloper

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 25

Page 26: Oracle ORDS 101 - Jumpstart your Development · 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

► ManagementoftheRESTdefini;onswithSQLDeveloper

► Createuseroncommandline

RESTDefini;onsManagementwithSQLDeveloper

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 26

Schema/Workspace will decide between APEX REST and ORDS REST

##UsertomanageRESTdefinitionsinSQLDeveloperjava-jarords.waruserdietmar.aust"SQLDeveloper”

Page 27: Oracle ORDS 101 - Jumpstart your Development · 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

► ManagementoftheRESTdefini;onswithSQLDeveloper

RESTDefini;onsManagementwithSQLDeveloper

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 27

Oracle REST Data Services

SQL Developer

http/https

APEX_050000

ORDS_METADATA

jdbc

jdbc authenticate and authorize user

Local filestore, Admin user needs role „SQLDeveloper“

Page 28: Oracle ORDS 101 - Jumpstart your Development · 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

► RESTcomponents▪  Modules

−  ResourceTemplates

−  Methods/Handlers(GET,PUT,POST,DELETE)

RESTDefini;onsModules,RessourceTemplatesandHandlers

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 28

Page 29: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 29

Demo

Page 30: Oracle ORDS 101 - Jumpstart your Development · 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

► ManagementthroughthePL/SQLAPI

► Simplefile…containsallresourcetemplatesandmethodsforamoduleinasingleplace

► Firstwedeletetheexis;ngdefini;onandthenwerecreateitfromscratch

► Verywellsuitedforscriptbaseddeployment

► APIreference(PackageORDS):h\p://docs.oracle.com/cd/E56351_01/doc.30/e56293/ords_ref.htm#AELIG90180

► UsePackageORDSinsteadofORDS_SERVICESinthefuture!!!

RESTDefini;onsManagementthroughtheAPI

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 30

Page 31: Oracle ORDS 101 - Jumpstart your Development · 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

► Handler–types▪  SQLQuery(legacy)(source_type_query)▪  SQLQuery(eineZeile)(legacy)(source_type_query_one_row)▪  Collec;on(source_type_collec;on_feed)▪  Collec;onItem(source_type_collec;on_item)▪  Feed(source_type_feed)▪  PL/SQL(source_type_plsql)

−  Generateeverythingmanuallymyself

▪  Media(source_type_media)−  Binaryrepresenta;ons

RESTDefini;onsHandler-Types

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 31

Page 32: Oracle ORDS 101 - Jumpstart your Development · 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

► Handler–Typ:SQLQuery(legacy)(source_type_query)▪  Containsalinktoitself

RESTDefini;onsHandler-Typen

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 32

selectemp.*fromemp

Page 33: Oracle ORDS 101 - Jumpstart your Development · 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

► Handler–TypSQL:SQLQuery(onerow)(legacy)(source_type_query_one_row)

RESTDefini;onsHandler-Typen

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 33

selectemp.*fromempwhereempno=:empno

Page 34: Oracle ORDS 101 - Jumpstart your Development · 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

► Handler–TypSQL:Collec;on(source_type_collec;on_feed)

► Completeincl.naviga;onlinks:▪  Self▪  Describedby▪  First(onlybypagina;onorlimit)▪  Next(onlybypagina;onorlimit)▪  Previous(onlybypagina;onorlimit)

RESTDefini;onsHandler-Typen

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 34

selectemp.*fromemp

Page 35: Oracle ORDS 101 - Jumpstart your Development · 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

► Handler–TypSQL:Collec;onItem(source_type_collec;on_item)▪  Containsalinktothecollec;onitself

RESTDefini;onsHandler-Typen

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 35

selectemp.*fromempwhereempno=:empno

Page 36: Oracle ORDS 101 - Jumpstart your Development · 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

► Handler–TypSQL:Feed(source_type_feed)

RESTDefini;onsHandler-Typen

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 36

selectemp.*fromemp

Page 37: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 37

UseCases

Page 38: Oracle ORDS 101 - Jumpstart your Development · 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

Firststep:EnableRESTcapabili;esforaschemainthedatabase

► UsingtheGUI(right-clickontheconnec;on)

► Usingthecommandline/API

UseCasesEnableRESTinSchema

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 38

BEGINORDS.ENABLE_SCHEMA(p_enabled=>TRUE,p_schema=>'ORDSTEST',p_url_mapping_type=>'BASE_PATH',p_url_mapping_pattern=>'ordstest',p_auto_rest_auth=>FALSE);COMMIT;END;

Page 39: Oracle ORDS 101 - Jumpstart your Development · 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

Implementnaviga;onlinkstonavigatebetweenthedifferentressources

► Linksusedfor:▪  Linktothecurrentrow▪  Linktoanimageoranembeddedlist(ressourceorderscancontainalisttothe

relatedorderitems)▪  Linktotheparent▪  Linktoother“siblings”usingrela;vepaths,e.g.../..

UseCasesNaviga;onandLinks

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 39

Page 40: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 40

Demo

Page 41: Oracle ORDS 101 - Jumpstart your Development · 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

ModifyressourcesusingPOST,PUTandDELETE

► Createanewressource(POST)

► Updatearessource(PUT)

► Deletearessource(DELETE)

UseCasesModifyressourcesusingPOST,PUTandDELETE

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 41

Demo

Page 42: Oracle ORDS 101 - Jumpstart your Development · 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

► RendereverythingmanuallywithPL/SQLyourself▪  GETwithTypPL/SQL▪  UseOWAToolkittowriteitout

−  APEX_JSON,PL/JSON

−  12cJSONFunk;onen

UseCasesPL/SQLHandler–implementeverythingyourself

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 42

Page 43: Oracle ORDS 101 - Jumpstart your Development · 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

► Displayanimage▪  GEThandler(typeMediaressource)

UseCasesMedia-Ressourcen

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 43

selectmimetype,product_imagefromdemo_product_infowhereproduct_id=to_number(:product_id)

Page 44: Oracle ORDS 101 - Jumpstart your Development · 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

► Pagina;on▪  Allowstopaginatethroughtheresultset▪  Onlyapplicableforhandlertypecollec;on(source_type_collec;on_feed)▪  h\p://docs.oracle.com/cd/E56351_01/doc.30/e56293/develop.htm#BABIHBDH▪  Pa\ern:GEThttp://<HOST>:<PORT>/ords/<SchemaAlias>/

<ObjectAlias>/?offset=<Offset>&limit=<Limit>▪  Alsocreatesthelinks“NEXT”,“PREVIOUS”und“FIRST”mit

► Example:

UseCasesPagina;on

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 44

Page 45: Oracle ORDS 101 - Jumpstart your Development · 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

► ResultSetFiltering▪  QuerySyntaxtofilteracollec;on▪  Onlyapplicableforhandlertypecollec;on(source_type_collec;on_feed)▪  h\p://docs.oracle.com/cd/E56351_01/doc.30/e56293/develop.htm#AELIG90104

► Sor;ng/OrderBy▪  QuerySyntaxtosortacollec;on▪  Onlyapplicableforhandlertypecollec;on(source_type_collec;on_feed)▪  h\p://docs.oracle.com/cd/E56351_01/doc.30/e56293/develop.htm#AELIG90104

UseCasesFilterandSort

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 45

Page 46: Oracle ORDS 101 - Jumpstart your Development · 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

► Inputparameters▪  Implicit

−  AllvariablesthatarepassedintheURLorinthecontentbody

−  :content_type(varchar2,z.B.applica;on/json)

−  :body(alsBLOB)

▪  Explicit(usingdeclatra;veparameters)−  Allregularh\pheadervariables

−  AllvariablesthatarepassedintheURLorinthecontentbody

UseCasesParameter

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 46

Page 47: Oracle ORDS 101 - Jumpstart your Development · 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

► Outputparameters▪  Explicit(usingdeclatra;veparameters)

−  Returnaresponsebyseyngasimplebindvariablewhichisthenconvertedautoma;callytoJSONbyORDS

−  Setanh\pResponseCode(Pseudo-Header:X-APEX-STATUS-CODE),e.g.201,403

−  RedirecttoadifferentURL(Pseudo-Header:X-APEX-FORWARD)

−  Setah\pheadervariable

UseCasesParameter

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 47

Page 48: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 48

Demo

Page 49: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 49

Security

Page 50: Oracle ORDS 101 - Jumpstart your Development · 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

► Differentwaysofauthen;ca;ngthecurrentuser▪  Authen;ca;onusingtheintegratedpasswordstore(“creden;als”file–just

recommendedfordevelopmentandtestenvironments)▪  Authen;ca;onusingtheapplica;onserver(authen;ca;onisdelegated,e.g.to

Glassfish)

► Authen;ca;onusingOAUTH2▪  Establishedstandard–usedwidely▪  Basicallycontrolsa“session”betweenclient/serverandyous;llneedto

authen;catewiththeappserver

► MoredetailstousingOAUTH2withORDS:Ar;clesfromCarstenCzarski(inGerman,butcanbetranslatedusingGoogleTranslator)▪  h\p://json-rest-oracledb.blogspot.de/2015/12/vorher-anmelden-bi\e-

authen;fizierung.html▪  h\p://json-rest-oracledb.blogspot.de/2016/01/ords-und-3-legged-oauth-so-

gehts.html

Security

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 50

Page 51: Oracle ORDS 101 - Jumpstart your Development · 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

► Authoriza;on:=Protectaccesstoressourcesforcertainuserroles

► CreateaROLEfirst(onlypossiblethroughtheAPI)

► CreateaprivilegetoprotectafullmoduleorjustaURIpa\ern

► Cannotrequireprotec;onjustforaspecificmethod,e.g.limitaccesstoPUT,POST,DELETEandallowGETforeverybody.▪  Perhapsusingtwomodules:

−  /public/departments/(implementGEThandler)

−  /protected/departments/(implementPOST,PUT,DELETEhandler)

Security

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 51

Page 52: Oracle ORDS 101 - Jumpstart your Development · 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

Security

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 52

Page 53: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 53

Demo

Page 54: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 54

Auto-REST

Page 55: Oracle ORDS 101 - Jumpstart your Development · 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

QuicklyAuto-RESTenableadatabasetableorview

► Pros:▪  Fastandeasy▪  CandosomecleverthingsusingINSTEAD_OFtriggersontheview

► Cons:▪  Can’tusetheauthen;cated:current_uservariabletofigureouttheuseriden;ty

whichisrequiredforloggingpurposes

Auto-REST

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 55

Page 56: Oracle ORDS 101 - Jumpstart your Development · 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

EnableRESTcapabili;esforatableorview

► UsingtheGUI(right-clickonthetable/view)▪  „EnableRESTService“

► Usingthecommandline/API

UseCasesEnableRESTinSchema

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 56

BEGINORDS.ENABLE_OBJECT(p_enabled=>TRUE,p_schema=>'ORDSTEST',p_object=>'DEPT',p_object_type=>'TABLE',p_object_alias=>'dept',p_auto_rest_auth=>FALSE);COMMIT;END;

Page 57: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 57

Demo

Page 58: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 58

Debugging/Troubleshoo;ng

Page 59: Oracle ORDS 101 - Jumpstart your Development · 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

► Displayerrormessagesdirectlyinthebrowser(onlyuseondevelopment/testenvironments,notproduc;on!)▪  Modifydefault.xml

► Fullloggingwithalldetailsusingjava.u;l.logging▪  h\ps://cdivilly.wordpress.com/2013/03/08/configuring-logging-in-oracle-

applica;on-express-listener-2-0-1/

Debugging/Troubleshoo;ng

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 59

<entrykey="debug.debugger">true</entry><entrykey="debug.printDebugToScreen">true</entry>

Page 60: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 60

Tools

Page 61: Oracle ORDS 101 - Jumpstart your Development · 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

► Commandlinetool:curl-h\ps://curl.haxx.se/

► AdvancedRESTClient(forGoogleChrome)▪  h\ps://chrome.google.com/webstore/detail/advanced-rest-client/

hgmloofddffdnphfgcellkdzzjeloo

► PLSQLlogger▪  h\ps://github.com/OraOpenSource/Logger

Tools

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 61

Page 62: Oracle ORDS 101 - Jumpstart your Development · 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

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 62

FurtherReading

Page 63: Oracle ORDS 101 - Jumpstart your Development · 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

► Slidestodownload:h\p://daust.blogspot.de

► Wikipedia:h\p://en.wikipedia.org/wiki/Representa;onal_State_Transfer

► REST–APIDesign▪  h\p://www.vinaysahni.com/best-prac;ces-for-a-pragma;c-res_ul-api▪  h\ps://www.thoughtworks.com/de/insights/blog/rest-api-design-resource-

modeling▪  h\p://blog.octo.com/en/design-a-rest-api/▪  h\ps://res_ul-api-design.readthedocs.org/en/latest/intro.html▪  h\p://blog.mwaysolu;ons.com/2014/06/05/10-best-prac;ces-for-be\er-res_ul-

api/

► CarstenCzarskiBlogaboutREST:h\p://json-rest-oracledb.blogspot.de/(canbetranslatedusinggoogletranslator)

FurtherReading

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 63

Page 64: Oracle ORDS 101 - Jumpstart your Development · 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

► RESTfulWebServices,byLeonardRichardsonandSamRuby,availablefromO’ReillyMediaath\p://oreilly.com/catalog/9780596529260/

► Thesource:h\p://www.ics.uci.edu/~fielding/pubs/disserta;on/top.htmmostlychapters5and6

► Anice14minutevideointroduc;on:h\p://www.youtube.com/watch?v=YCcAE2SCQ6k

► HTTPspec:h\p://tools.ie_.org/html/rfc2616

► URIspec:h\p://tools.ie_.org/html/rfc3986

► JSONformat:h\p://json.org/

WeitereInforma;onsquellen

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 64

Page 65: Oracle ORDS 101 - Jumpstart your Development · 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

1-DayDeveloperWorkshopORDS► InCologneinJune(inGerman)

► OnlineasafulldaywebinarinJuly(inEnglish)

► Topics▪  Setup/configura;onforAPEX/mod_plsqlandREST▪  RealWorldproject(morecomplexexamples)▪  Differentusecaseswithlotsofhands-ons▪  Authen;ca;onusingWLS,GlassfishandTomcat▪  OAUTH2flowimplementa;on

1-DayDeveloperWorkshop

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 65

Page 66: Oracle ORDS 101 - Jumpstart your Development · 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

Contact

02.02.2016 Oracle ORDS 101 - Jumpstart your Development Page 66

DietmarAustOpal-Consul;ng,Kölnwww.opal-consul;ng.dedaust.blogspot.comdietmar.aust@opal-consul;ng.de