Write operations
- Last Updated: August 15, 2023
- 3 minute read
- DataDirect Connectors
- ODBC
- Autonomous Rest Connector 8.0
- Documentation
To execute Insert, Update, and Delete statements against your data, you must first
configure the corresponding write operation directives in the table definition. The values
specified for the directives contain the REST verb to use for the operation and the endpoint
for which you want the corresponding write operation enabled. For example, if you want to
enable Insert statements for your endpoint, you must specify your endpoint using the #insert directive. See "Insert", "Update", and "Delete" for more
information on SQL statement syntax.
#readOnly directive. Designating columns as read-only prevents data
stored within from being inadvertently changed. See "Read-only columns" for examples and
more information. A table entry with insert, update, and delete operations enabled would take the following form:
"<table_name>": {
"#path": ["<host_name_1/<endpoint_path_1>","<host_name_2/<endpoint_path_2>",...],
"#insert": "<http_method> <host_name>/<operation_path>",
"#update": "<http_method> <host_name>/<operation_path>",
"#delete": "<http_method> <host_name>/<operation_path>",
<column_definitions>
},
Note that if your endpoint definitions require that you pass the values to
be inserted or updated in an array in the POST body, then add square brackets ([] ) to the endpoint definition in the write operation
directive:
"<table_name>": {
"#path": ["<host_name_1/<endpoint_path_1>","<host_name_2/<endpoint_path_2">,...],
"#insert": "<http_method> <host_name>/<operation_path>[]",
"#update": "<http_method> <host_name>/<operation_path>[]",
<column_definitions>
},
- table_name
- is the name of the relational table to which the driver maps the endpoint. For example, countries.
- host_name
- (optional) is the protocol and host name components of the URL endpoint. For example, http://example.com. You can omit this value by specifying the host name using the ServerName property.
- endpoint_path
- is the path component of the URL endpoint. For example,
country. This can be an unparameterized or parameterized path, a path that uses query parameters, or an array of paths. See "Query paths" for examples and more information. - http_method
- (optional) is the HTTP method used to perform the request for the specified write
operation. By default, this method is
POSTfor inserts,PUTfor updates, andDELETEfor deletes. The default values will work for many REST services; however, you may need to specify a different method according to the expectations of your API. - operation_path
- is the path component of the URL endpoint against which a write operation can be
performed. For example,
country. This can be an unparameterized or parameterized path, a path that uses query parameters, or an array of paths. See "Query paths" for examples and more information.
For example, the following entry enables Insert and Delete statements to
be executed against data in the specified endpoint and the Countries table.
"Countries": {
"#path": ["http://example.com/countries/",
"http://example.com/countries/{id}"],
"#insert": "http://example.com/countries/",
"#delete": "http://example.com/countries/{id}",
"id":"VarChar(32),#key,"
"name":"VarChar(46)",
"population":"Integer"
},
The following example demonstrates an entry that enables the driver to insert the contents of an array element in a POST body.
"Countries": {
"#path": ["http://example.com/countries/",
"http://example.com/countries/{id}"],
"#insert": "http://example.com/countries/{id}[]",
"id":"VarChar(32),#key",
"name":"VarChar(46)",
"population":"Integer"
},
Passing the primary key in the body of a request
#insert |
#update) after the #key directive. In the following
example, the primary key is passed in the body of insert and update operations because the
#insert and #update directives are specified in the
column definition of the primary key. {
"Countries":{
"#path": ["http://example.com/countries/",
"http://example.com/countries/{id}"]
"#insert":"http://example.com/countries/{id}",
"#update":"http://example.com/countries/{id}",
"id":"VarChar(32),#key,#insert,#update",
"name":"VarChar(46),#readOnly",
"population":"Integer"
}
},