This article will get you started with using ORDS 3.0.0 to create RESTful Services using the new PL/SQL API.
Before you go any further you’ll need to download and install Oracle REST Data Services. Click here for instructions on how to get ORDS up and running in under 5 minutes.
You’ll also need to enable a database schema to try out the steps in this article. Click here for instructions on how to enable a schema for use with ORDS, it’ll only take a minute to do.
Connect to the ORDS enabled database schema, in this article we’ll assume
you are using the ordstest
schema created by following the instructions
mentioned above
|
|
Let’s create a Hello World example using the PL/SQL API:
|
|
This call does the following:
examples.routes
/examples/routes
greeting/:name
GET
handler and set it’s source as an SQL query that forms a short
greeting.
GET
is the default value for the p_method
argument, and is used here, because the p_method
argument was omitted.COLLECTION_FEED
is the default value for the p_source_type
argument,
and is used here, because the p_source_type
argument was omitted.who
.Start up ORDS:
|
|
visit the URI of the RESTful Service we just created in a browser:
http://localhost:8080/ords/ordstest/examples/routes/greeting/joe
localhost
and listening on port
8080
, adjust these values if your configuration differs to these values.If you have a JSON viewing extension installed in your browser you’ll see something like the following:
|
|
Note how the URL does not include a who
query parameter. Therefore the
:who
bind parameter is bound to the null
value, which causes the query
to use the value of the current database user
(sys_context(''USERENV'',''CURRENT_USER'')
) instead.
Let’s try another URL, this time supplying a who
query parameter:
http://localhost:8080/ords/ordstest/examples/routes/greeting/joe?who=jane
This time the result will look like the following:
|
|
Note how the ORDSTEST
value has been replaced by the jane
value, as this
time the :who
bind parameter was bound to the jane
value.