Autonomous Database supports Simple
Oracle Document Access (SODA) for REST.
Overview of Using SODA for REST SODA for REST is a predeployed REST service that can be used to store JSON documents in your database.
Load Purchase-Order Sample Data Using SODA for REST Oracle provides a substantial set of JSON purchase-order documents, in plain-text file POList.json, as a JSON array of objects, where each such object represents a document.
Use SODA for REST with OAuth Client Credentials You can access SODA for REST on Autonomous Database using OAuth authentication. Depending on your application, accessing SODA for REST with OAuth authentication can improve performance and security.
SODA for REST is a predeployed REST service that
can be used to store JSON documents in your database.
SODA enables flexible, NoSQL-style
application development without having to use SQL. With SODA, JSON documents are stored
in named collections and managed using simple CRUD operations (create, read, update and
delete). And while SQL isn't required, JSON stored in SODA collections is still fully
accessible from SQL when needed. For example, an operational application may be fully
built using SODA (without SQL) but then the data may be later analyzed using SQL from
outside of the application. Autonomous Database SODA gives application developers the best of the NoSQL and SQL worlds
- fast, flexible, and scalable application development without losing the ability to
leverage SQL for analytics and reporting.
SODA for REST is deployed in ORDS under the following URL pattern, where
schema corresponds to a REST-enabled database
schema.
/ords/schema/soda/latest/*
The following examples use the cURL command line tool (http://curl.haxx.se/) to submit REST requests to the database. However, other
3rd party REST clients and libraries should work as well. The examples use database
schema ADMIN, which is REST-enabled. You can SODA for REST with
cURL commands from the Oracle Cloud Shell.
This command creates a new collection named "fruit" in the
ADMIN schema:
> curl -X PUT -u 'ADMIN:<password>' \
"https://example-db.adb.us-phoenix-1.oraclecloudapps.com/ords/admin/soda/latest/fruit"
These commands insert three JSON documents into the fruit
collection:
SELECT
f.json_document.name,
f.json_document.count,
f.json_document.color
FROM fruit f;
The query returns these three rows:
name count color
--------- --------- -------
orange 42 null
pear 5 null
apple 12 red
Note
If you are using Always Free Autonomous Database with Oracle Database 23ai, Oracle recommends the following:
For projects that were started using a database release prior to Oracle Database 21c, explicitly specify the metadata for
the default collection as specified in the example in the section SODA Drivers.
For projects started using release Oracle Database 21c
or later, just use the default metadata. See SODA Drivers for more
information.
These examples show a subset of the SODA and SQL/JSON features. See the
following for more information:
SODA for REST for
complete information on Simple Oracle Document Access (SODA)
Load Purchase-Order Sample Data
Using SODA for REST ๐
Oracle
provides a substantial set of JSON purchase-order documents, in plain-text file
POList.json, as a JSON array of objects, where each such
object represents a document.
The following examples use the cURL command line tool (http://curl.haxx.se/) to submit REST
requests to the database. However, other 3rd party REST clients and
libraries should work as well. The examples use database schema
ADMIN, which is REST-enabled. You can use
SODA for REST with cURL commands from the Oracle Cloud
Shell.
You can load this sample purchase-order data set into a
collection purchaseorder on your Autonomous Database
with SODA for REST, using these curl commands:
curl -X GET "https://raw.githubusercontent.com/oracle/db-sample-schemas/master/order_entry/POList.json" -o POList.json
curl -X PUT -u 'ADMIN:password' \
"https://example-db.adb.us-phoenix-1.oraclecloudapps.com/ords/admin/soda/latest/purchaseorder"
curl -X POST -H -u 'ADMIN:password' 'Content-type: application/json' -d @POList.json \
"https://example-db.adb.us-phoenix-1.oraclecloudapps.com/ords/admin/soda/latest/purchaseorder?action=insert"
For example, the following query selects both the id of
a JSON document and values from the JSON purchase-order collection
stored in column json_document of table
purchaseorder. The values selected are from
fields PONumber, Reference, and
Requestor of JSON column
json_document, which are projected from the
document as virtual columns (see SQL NESTED
Clause Instead of JSON_TABLE for more
information).
Use SODA for REST with OAuth
Client Credentials ๐
You can
access SODA for REST on Autonomous Database using OAuth authentication. Depending on your application,
accessing SODA for REST with OAuth authentication can improve performance and
security.
Perform the following steps to use OAuth authentication to
provide limited access to SODA for REST on Autonomous Database:
As the ADMIN user, access Database Actions and create a user
with the required privileges.
This registers a client named
my_client to access the
my_priv privilege using OAuth
client credentials.
Obtain the client_id and
client_secret required to generate
the access token.
For example, in the SQL worksheet run the
following command:
SELECT id, name, client_id, client_secret FROM user_ords_clients;
Obtain the access token. To get an access token you send a
REST GET request to
database_ORDS_urluser_name/oauth/token.
The
database_ORDS_url is
available from Database Actions, under
Related Services, on the
RESTful Services and Soda
card. See Access RESTful Services and SODA for REST for more information.
In the following command, use the
client_id and the
client_secret you obtained in
Step 6.
The following example uses the
cURL command line tool (http://curl.haxx.se/) to submit REST
requests to Autonomous Database. However, other 3rd party REST clients
and libraries should work as well.
You can
use the cURL command line tool to
submit the REST GET request. For
example:
To specify both the client_id and the
client_secret with the curl
--user argument, enter a colon to
separate the client_id and the
client_secret. If you only
specify the user name, client_id,
curl prompts for a password and you can enter the
client_secret at the prompt.
Use the access token to access the protected resource.
The token obtained in the previous step is
passed in the Authorization header. For example: