4 SODA for REST HTTP Operations

The SODA for REST HTTP operations are described.

Table 4-1 summarizes the HTTP operations that SODA for REST provides. For complete descriptions of the operations, click the links in the left column.

Table 4-1 SODA for REST HTTP Operations

Operation Description

GET schema

Gets some or all collection names in a schema.

GET collection

Gets all or a subset of objects from a collection, using parameters to specify the subset. You can page through the return set.

GET object

Gets a specified object from a collection.

PUT collection

Creates a collection if it does not exist.

PUT object

Replaces a specified object with an uploaded object (typically a new version).

If the collection has client-assigned keys and the uploaded object is not already in the collection, then PUT inserts the uploaded object into the collection.

DELETE collection

Deletes a collection.

DELETE object

Deletes a specified object from a collection.

POST object

Puts an uploaded object in a specified collection, assigning and returning its key. Collection must use server-assigned keys.

POST query

Gets all or a subset of objects from a collection, using a filter to specify the subset. You cannot page through the return set.

POST array insert

Inserts an array of objects into a specified collection, assigning and returning their keys.

POST bulk delete

Deletes all or a subset of objects from a collection.

4.1 SODA for REST HTTP Operation URIs

A SODA for REST HTTP operation is specified by a Universal Resource Identifier (URI).

The URI has this form:

/ords/schema/soda/[version/[collection/[{key/|?action=action}]]]

where:

  • ords is the directory of the Oracle REST Data Services (ORDS) listener, of which SODA for REST is a component.

  • schema is the name of an Oracle Database schema that has been configured as an end point for SODA for REST.

  • soda is the name given to the Oracle Database JSON service when mapped as a template within ORDS.

  • version is the version number of soda.

  • collection is the name of a set of objects stored in schema.

    Typically, an object is a JSON document, but it can be a Multipurpose Internet Mail Extensions (MIME) type (for example, image, audio, or video).

    A JSON document is represented as textual JSON.

    Typically, an application uses a collection to hold all instances of a particular type of object. Thus, a collection is roughly analogous to a table in a relational database. One column stores keys and another column stores content.

  • key is a string that uniquely identifies an object in collection.

    A specified object is specified by its key.

  • action is either query, index, unindex, insert, update, or delete.

4.2 SODA for REST HTTP Operation Response Bodies

If a SODA for REST HTTP operation returns information or objects, it does so in a response body.

For the operation GET object, the response body is a single object.

Table 4-2 lists and describes fields that can appear in response bodies.

Table 4-2 Fields That Can Appear in Response Bodies

Field Description

key

String that uniquely identifies an object (typically a JSON document) in a collection.

etag

HTTP entity tag (ETag)—checksum or version.

created

Created-on time stamp.

lastModified

Last-modified time stamp.

value

Object contents (applies only to JSON object).

mediaType

HTTP Content-Type (applies only to non-JSON object).

bytes

HTTP Content-Length (applies only to non-JSON object).

items

List of one or more collections or objects that the operation found or created. This field can be followed by the fields in Table 4-3.

If an operation creates or returns objects, then its response body can have the additional fields in Table 4-3. The additional fields appear after field items.

Table 4-3 Additional Response Body Fields for Operations that Return Objects

Field Description

name

Name of collection. This field appears only in the response body of GET schema.

properties

Properties of collection. This field appears only in the response body of GET schema.

hasMore

true if limit was reached before available objects were exhausted, false otherwise. This field is always present.

limit

Server-imposed maximum collection (row) limit.

offset

Offset of first object returned (if known).

count

Number of objects returned. This is the only field that can appear in the response body of POST bulk delete.

totalResults

Number of objects in collection (if requested)

links

Possible final field for GET collection operation. For details, see GET collection.

Example 4-1 shows the structure of a response body that returns 25 objects. The first object is a JSON object and the second is a jpeg image. The collection that contains these objects contains additional objects.

Example 4-1 Response Body

{

  "items" : [
    {
      "id"           : "key_of_object_1",
      "etag"         : "etag_of_object_1",
      "lastModified" : "lastmodified_timestamp_of_object_1",
      "value"        : {object_1}
    },
    {
      "id"           : "key_of_object_2",
      "etag"         : "etag_of_object_2",
      "lastModified" : "lastmodified_timestamp_of_object_2",
      "mediaType"    : "image/jpeg",
      "bytes"        : 1234
    },
    ...
  ],
  "hasMore" : true,
  "limit"   : 100,
  "offset"  : 50,
  "count"   : 25
  "links"   : [ ... ]
}

4.3 GET schema

GET schema gets all or a subset of collection names in a schema.

4.3.1 URL Pattern for GET schema

The URL pattern for GET schema is described.

/ords/schema/soda/version/

Without parameters, GET schema gets all collection names in schema.

Parameter Description

limit=n

Limits number of listed collection names to n.

fromID=collection

Starts getting with collection (inclusive).

4.3.2 Response Codes for GET schema

The response codes for GET schema are described.

200

Success—response body contains names and properties of collections in schema, ordered by name. For example:

{
  "items" : [
    {"name"        : "employees",
     "properties" : {...} },
    {"name"        : "departments",
     "properties" : {...} },
    ...
  ],
  "hasMore" : false
}

If hasMore is true, then to get the next batch of collection names specify fromID=last_returned_collection. (In the preceding example, last_returned_collection is "regions").

404

Either the schema was not found or access is not authorized.

4.4 GET collection

GET collection gets all or a subset of objects from a collection, using parameters to specify the subset. You can page through the set of returned objects.

See Also:

4.4.1 URL Pattern for GET collection

The URL pattern for GET collection is described.

/ords/schema/soda/version/collection/

Without parameters, GET collection gets all objects (both key and content) from collection and does not return the number of objects in collection.

Note:

For non-JSON objects in the collection, GET collection returns, instead of content, media type and (if known) size in bytes.

Parameter Description

limit=n

Limits number of objects to n.

offset=n

Skips n objects before getting first object.

fields={id|value|all}

Gets only object id fields (keys), only object value fields (content), or all fields (both key and content).

Regardless of the fields value, GET collection returns the other metadata that the collection stores for each document.

totalResults=true

Returns number of objects in collection. Note: Inefficient

fromID=key

Starts getting objects after key, in ascending order.

toID=key

Stops getting objects before key, in descending order.

after=key

Starts getting objects after key, in ascending order.

before=key

Stops getting objects before key, in descending order.

since=timestamp

Gets only objects with time stamp later than timestamp.

until=timestamp

Gets only objects with time stamp earlier than timestamp.

4.4.2 Response Codes for GET collection

The response codes for GET collection are described.

200

Success—response body contains the specified objects from collection (or only their keys, if you specified fields=id). For example:

{
  "items" : [
    {
      "id"           : "key_of_object_1",
      "etag"         : "etag_of_object_1",
      "lastModified" : "lastmodified_timestamp_of_object_1",
      "value"        : {object_1}
    },
    {
      "id"           : "key_of_object_2",
      "etag"         : "etag_of_object_2",
      "lastModified" : "lastmodified_timestamp_of_object_2",
      "value"        : {object_2}
    },
    {
      "id"           : "key_of_object_3",
      "etag"         : "etag_of_object_3",
      "lastModified" : "lastmodified_timestamp_of_object_3",
      "mediaType"    : "image/jpeg",
      "bytes"        : 1234
    },
    ...
  ],
  "hasMore" : true,
  "limit"   : 100,
  "offset"  : 50,
  "count"   : 25
  "links"   : [ ... ]
}

If hasMore is true, then to get the next batch of objects repeat the operation with an appropriate parameter. For example:

  • offset=n if the response body includes the offset

  • toID=last_returned_key or before=last_returned_key if the response body includes descending=true

  • fromID=last_returned_key or after=last_returned_key if the response body does not include descending=true

For information about links, see Links Array for GET collection.

401

Read access to collection is not authorized.

404

Collection was not found.

4.4.3 Links Array for GET collection

The links array for GET collection is described.

The existence and content of the links array depends on the mode of the GET collection operation, which is determined by its parameters.

When the links array exists, it has an element for each returned object. Each element contains links from that object to other objects. The possible links are:

  • first, which links the object to the first object in the collection

  • prev, which links the object to the previous object in the collection

  • next, which links the object to the next object in the collection

Using prev and next links, you can page through the set of returned objects.

Table 4-4 shows how GET collection parameters determine mode and the existence and content of the links array.

Table 4-4 Relationship of GET collection Parameters to Mode and Links Array

Parameter Mode Links Array

fields=id

Keys-only

Does not exist (regardless of other parameters).

offset=n

Offset

Has an element for each returned object. Each element has these links, except as noted:

  • first (except for first object)

  • prev (except for first object)

  • next (except for last object)

fromID=key

toID=key

after=key

before=key

Keyed

Has an element for each returned object. Each element has these links, except as noted:

  • prev (except for first object)

  • next (except for last object)

since=timestamp

until=timestamp

Timestamp

Does not exist.

4.5 GET object

GET object gets a specified object from a specified collection.

4.5.1 URL Pattern for GET object

The URL pattern for GET object is described.

/ords/schema/soda/version/collection/key/

No parameters.

4.5.2 Request Headers for GET object

The request headers for GET object are described.

Operation GET object accepts these optional request headers:

Header Description

If-Modified-Since=timestamp

Returns response code 304 if object has not changed since timestamp.

If-None-Match

Returns response code 304 if object etag matches the current checksum or version.

4.5.3 Response Codes for GET object

The response codes for GET object are described.

200

Success—response body contains object identified by the URL pattern.

204

Object content is null.

304

Either object was not modified since modification date or checksum matches object etag (see Request Headers for GET object).

401

Read access to collection or object is not authorized.

404

Collection or object was not found.

4.6 PUT collection

PUT collection creates a collection if it does not exist.

4.6.1 URL Pattern for PUT collection

The URL pattern for PUT collection is described.

/ords/schema/soda/version/collection/

No parameters.

4.6.2 Request Body for PUT collection (Optional)

The request body for PUT collection is described.

4.6.3 Response Codes for PUT collection

The response codes for PUT collection are described.

200

Collection with the same name and properties already exists.

201

Success—collection was created.

401

Collection creation is not authorized.

4.7 PUT object

PUT object replaces a specified object in a specified collection with an uploaded object (typically a new version). If the collection has client-assigned keys and the uploaded object is not already in the collection, then PUT inserts the uploaded object into the collection.

4.7.1 URL Pattern for PUT object

The URL pattern for PUT object is described.

/ords/schema/soda/version/collection/key/

No parameters.

4.7.2 Request Body for PUT object

The request body for PUT object is the uploaded object.

4.7.3 Response Codes for PUT object

The response codes for PUT object are described.

200

Success—object was replaced.

401

Updating collection is not authorized.

405

Collection is read-only.

4.8 DELETE collection

DELETE collection deletes a collection.

To delete all objects from a collection, but not delete the collection itself, use POST bulk delete.

4.8.1 URL Pattern for DELETE collection

The URL pattern for DELETE collection is described.

/ords/schema/soda/version/collection/

No parameters.

4.8.2 Response Codes for DELETE collection

The response codes for DELETE collection are described.

200

Success—collection was deleted.

401

Deleting collection is not authorized.

404

Collection was not found.

4.9 DELETE object

DELETE object deletes a specified object from a specified collection.

4.9.1 URL Pattern for DELETE object

The URL pattern for DELETE object is described.

/ords/schema/soda/version/collection/key/

No parameters.

4.9.2 Response Codes for DELETE object

The response codes for DELETE object are described.

200

Success—object was deleted.

401

Either deleting from collection or deleting this object is not authorized.

404

Object was not found.

405

Collection is read-only.

4.10 POST object

POST object inserts an uploaded object into a specified collection, assigning and returning its key. The collection must use server-assigned keys.

If the collection uses client-assigned keys, use PUT object. For information about key assignment methods, see Key Assignment Method.

4.10.1 URL Pattern for POST object

The URL pattern for POST object is described.

/ords/schema/soda/version/collection/

No parameters.

4.10.2 Request Body for POST object

The request body for POST object is the uploaded object to be inserted in the collection.

4.10.3 Response Codes for POST object

The response codes for POST object are described.

201

Success—object is in collection; response body contains server-assigned key and possibly other information. For example:

{
  "items" : [
    {
      "id"           : "key",
      "etag"         : "etag",
      "lastModified" : "timestamp"
      "created"      : "timestamp"
    }
  ],
  "hasMore" : false
}

202

Object was accepted and queued for asynchronous insertion; response body contains server-assigned key.

401

Inserting into collection is not authorized.

405

Collection is read-only.

501

Unsupported operation (for example, no server-side key assignment).

4.11 POST query

POST query gets all or a subset of objects from a collection, using a filter to specify the subset. You cannot page through the set of returned objects.

See Also:

4.11.1 URL Pattern for POST query

The URL pattern for POST query is described.

/ords/schema/soda/version/collection?action=query

Parameters are optional except as noted.

Parameter Description

action=query

Required. Specifies kind of action.

limit=n

Limit number of returned objects to n.

offset=n

Skip n objects before returning objects.

fields={id|value|all}

Return object id (key) only, object value (content) only, or all (object key and content). Default: all

4.11.2 Request Body for POST query

If you omit the filter specification object from the request body of POST query then the operation gets all objects in the collection.

See Also:

Oracle Database Introduction to Simple Oracle Document Access (SODA) for information about SODA filter specifications.

4.11.3 Response Codes for POST query

The response codes for POST query are described.

200

Success—object is in collection; response body contains all objects in collection that match filter.

404

Either collection was not found or read access to collection is not authorized.

4.12 POST array insert

POST array insert inserts an array of objects into a specified collection, assigning and returning their keys.

4.12.1 URL Pattern for POST array insert

The URL pattern for POST array insert is described.

/ords/schema/soda/version/collection?action=insert
Parameter Description

action=insert

Required. Specifies kind of action.

4.12.2 Request Body for POST array insert

The request body for POST array insert is an array of objects.

Array of objects.

4.12.3 Response Codes for POST array insert

The response codes for POST array insert are described.

200

Success—response body contains an array with the assigned keys for inserted objects. For example:

{
  "items" : [
    {
      "id"           : "12345678",
      "etag"         : "...",
      "lastModified" : "..."
      "created"      : "..."
    },
    {
      "id"           : "23456789",
      "etag"         : "...",
      "lastModified" : "..."
      "created"      : "..."
    }
  ],
  "hasMore" : false
}

401

Inserting into collection is not authorized.

404

Collection was not found.

405

Collection is read-only.

4.13 POST bulk delete

POST bulk delete deletes all or a subset of objects from a specified collection, using a filter to specify the subset.

Note:

If you delete all objects from the collection, the empty collection continues to exist. To delete the collection itself, use DELETE collection.

4.13.1 URL Pattern for POST bulk delete

The URL pattern for POST bulk delete is described.

Either of the following:

/ords/schema/soda/version/collection?action=delete

/ords/schema/soda/version/collection?action=truncate
Parameter Description

action=delete

Required. Specifies the deletion of all or a subset of objects from collection, using an optional filter to specify the subset. See the following warning.

action=truncate

Required. Specifies the deletion of all objects from collection. Does not use a filter.

WARNING:

If you specify action=delete and omit the filter specification, or if the filter specification is empty, then the operation deletes all objects from the collection.

4.13.2 Request Body for POST bulk delete (Optional)

See Oracle Database SODA for Java Developer's Guide for information about SODA filter specifications.

4.13.3 Response Codes for POST bulk delete

The response codes for POST bulk delete are described.

200

Success—response body contains number of deleted collections. For example:

{
  "count" : 42
}

401

Deleting from collection is not authorized.

405

Collection is read-only.