Update: November 2011, This functionality is available in Oracle Application Express Listener 1.1 and later, note the syntax of bind variables has been changed to match that used in other Oracle products: {person}
becomes :person
. The examples below have been changed to reflect the updated syntax Oracle Application Express Listener Early Adopter Release 1.1 introduces a feature called Resource Templates that enables quick and easy configuration of RESTful web services for exposing and manipulating data stored in an Oracle Database via HTTP.
Resource Templates are a mechanism to bind a URI Template to an SQL Query or a PL/SQL Block. For example a Resource Template could bind the URI Template: hello?who={person}
to the following SQL Query:
|
|
Note how the {person}
parameter in the URI Template is bound to a similarly named variable (:person
) in the SQL query. Suppose our Application Express Listener is deployed at: http://example.com/apex/
then a HTTP request like the following:
GET /apex/hello?who=World HTTP/1.1 Host: example.com
will generate a HTTP response like the following:
HTTP/1.1 200 OK
ETag: "vovmx3pCoUq/DcdTY/hXusiq1QU="
Content-Type: application/json
{ "greeting": "Hello World from Oracle Application Express Listener" }
hello?who=World
is received by the Application Express Listener, it is matched against our Resource Template’s URI Template.World
is used as the value for :person
parameterNote the ETag
header in the HTTP response of the previous example. An ETag
is a version identifier for a resource, in other words whenever the content of a resource changes, the value of its ETag
header also changes. Resource Templates can generate an ETag
header as follows:
ETag
value. This option does not require buffering of the resource, but care needs to be taken to ensure the SQL query does guarantee a different result set for each resource versionETag
. Naturally there is an option to suppress generation of an ETag
headerResource Templates have an automatic capability for handling HTTP Conditional Operations where a If-None-Match
or If-Match
header is included with a request. To follow on from the example in the previous section a HTTP request like the following:
GET /apex/hello?who=World HTTP/1.1
Host: example.com
If-None-Match: "vovmx3pCoUq/DcdTY/hXusiq1QU="
will generate a HTTP response like the following:
HTTP/1.1 304 Not Modified
hello?who=World
is received by the Application Express Listener, it is matched against our Resource Template’s URI Template.If-None-Match
header304 Not Modified
response and does not include the resource’s content in the responseResource Templates can be used to generate any type of resource not just the default of JSON documents. Resource Templates support a special type of SQL query called a Media Resource Query. Media Resource Queries consist of an SQL Query that generate a single result row with two columns in the row. The first column denotes the resource’s MIME type, the second column contains the resource’s content. For example if we have a Resource Template with a URI Template of : customers/locations/{state}
bound to the following query:
|
|
Then a HTTP request like:
GET /apex/customers/locations/ny HTTP/1.1
Host: example.com
will generate a HTTP response like:
HTTP/1.1 200 OK
ETag: "P4eISUyr2BZwtN1VnQHYyV556wU="
Content-Type: application/vnd.google-earth.kml+xml
<kml
xmlns="http://www.opengis.net/kml/2.2">
<Folder>
<name>NY</name>
<Placemark>
<name>Blake Seignier</name>
<Point>
<coordinates>-76.14607,43.106533,0</coordinates>
</Point>
</Placemark>
...
</Folder>
</kml>
The above gives a brief flavour of what Resource Templates can accomplish, but there’s lots more functionality, here’s a few highlights:
Accept-Language
headerYou can download the Early Adopter Release here. The Developer Guide provides all the information needed to get started with Resource Templates. The latest version of Oracle Application Express Listener can be downloaded here. The Developer Guide provides all the information needed to get started with Resource Templates.
This is an Early Adopter release, it is not a finished product, As ever we encourage you to try out Oracle Application Express Listener and tell us what you think in the Oracle Application Express Listener forum. We look forward to your feedback.