Data Sources
List of Sources
You can access the list of data sources present in the system by executing the following GET request:
GET http://<cdatavirtuality-server-address>:8080/rest/api/source
STATUS 200
[
{"Name":"SYS"},
{"Name":"SYSADMIN"},
{"Name":"UTILS"},
{"Name":"SYSLOG"},
{"Name":"views"}
]
Source Content
The content of each source (tables, views, and stored procedures) can be accessed by the following GET request:
GET http://<cdatavirtuality-server-address>:8080/rest/api/source/{name}
STATUS 200
[
{"Name":"CliTemplates","Type":"Table","Description":null,"SchemaName":"SYSADMIN"},
{"Name":"DVConnectorPropDefaults","Type":"Table","Description":null,"SchemaName":"SYSADMIN"},
{"Name":"dropIndexByName","Type":"Procedure","Description":null,"SchemaName":"SYSADMIN"}
]
If the requested source is missing, status 404 with an explanatory message will be returned. In the following example, the problem is caused by a typo in the schema name:
STATUS 404
{"title":"Something is wrong","description":"Schema 'sysadmind' doesn't exist.","hint":null}
Operations with Sources
Removing Source
A source can be removed using the DELETE
method.
DELETE http://<cdatavirtuality-server-address>:8080/rest/api/source/{source}
STATUS 200
// No content in response
However, if the source is missing, the following message will appear:
DELETE http://<cdatavirtuality-server-address>:8080/rest/api/source/{source}
STATUS 404
{"title":"Something is wrong","description":"Schema 'doesntexist' doesn't exist.","hint":null}
Adding Source
A new source can be added using a POST
request. Please note that the request body should strictly follow the given template:
POST http://<cdatavirtuality-server-address>:8080/rest/api/source/
Body (application/json):
{
"name":"trackNtrace",
"template":"ws",
"translator":"dhl",
"connectionProps":"",
"modelProps":"",
"translatorProps":"",
"encryptedProperties":""
}
STATUS 200
// No content in response
Retrieving Table Content
To access the content of a particular table, you can use the following GET
request:
GET http://<cdatavirtuality-server-address>:8080/rest/api/source/{source-name}/{table-name}
STATUS 200
[{"id":2, "Name":"test"}, {"id":3, "Name":"newone"}]
If you want to reduce the amount of data transferred, you might want to use an SQL query endpoint with array=true
. It uses 2D array instead of the JSON objects collection (see Example 1 in SQL Queries). If the table is missing, you will see the following message:
GET http://<cdatavirtuality-server-address>:8080/rest/api/source/{source-name}/{table-name}
STATUS 404
{"title":"Something is wrong","description":"Table 'doesntexist' doesn't exist.","hint":null}
Retrieving Row Content by Primary Key
To access the content of a particular row by a primary key value, you can use the following GET
request:
GET http://<cdatavirtuality-server-address>:8080/rest/api/source/{source-name}/{table-name}/{primary-key-value}
STATUS 200
[{"id":2, "Name":"test"}]
Retrieving Table Content by Column Value
To access the rows of a particular table that fulfil some column value (like in a query with a WHERE
clause), you can use the following GET
request:
GET http://<cdatavirtuality-server-address>:8080/rest/api/source/{source-name}/{table-name}/{column-name}/{column-value}
STATUS 200
[{"num":2, "Name":"test"}, {"num":2, "Name":"newone"}]
Retrieving row content by primary key and retrieving table content by column value available since v4.5
Calling Stored Procedure
Stored procedures can be invoked from REST API as well. Calling parameters should be provided in the request's body. Stored procedures may return an empty array, an array with a single object, or an array with multiple objects.
POST http://<cdatavirtuality-server-address>:8080/rest/api/source/{source-name}/{procedure-name}
Body (application/json):
{"param" : "please md5 it"}
// or
[{"param" : "please md5 it"}]
STATUS 200
[{"hash":"4BC3338E788464C21918D09A64AB6212"}]
If the stored procedure is missing, you will see status 404 accompanied by the following message:
POST http://<cdatavirtuality-server-address>:8080/rest/api/source/{source-name}/{procedure-name}
STATUS 404
{"title":"Something is wrong","description":"Procedure 'doesntexist' doesn't exist.","hint":null}
Calling Stored Procedure in Bulk Mode
There is a way to call a procedure in the bulk mode with one POST
request. In this case, the response will contain a result for each set of parameters sent to the stored procedure. These results will then be marked as the original name of the called stored procedure and concatenated with "_index", to separate the results from one call to the stored procedure from the next call. For example, if the procedure has two parameters a
and b
, the HTTP body could look like this, representing two procedure calls:
POST http://<cdatavirtuality-server-address>:8080/rest/api/{source-name}/{procedure-name}
Request:
POST http://<cdatavirtuality-server-address>:8080/rest/api/SYSADMIN/md5
Body (application/json):
'[{"param" : "please md5 this"},{"param" : "and this"}]'
STATUS 200
[
{
"md5_1": [
{
"hash": "305CD7369E8475B593E6CF04C0E02181"
}
]
},
{
"md5_2": [
{
"hash": "EB21B32F360D0B91F188219FB46F6B77"
}
]
}
]
If the stored procedure is missing, you will see status 404 accompanied by the following message:
POST http://<cdatavirtuality-server-address>:8080/rest/api/source/{source-name}/{procedure-name}
STATUS 404
{"title":"Something is wrong","description":"Procedure 'doesntexist' doesn't exist.","hint":null}
Viewing Response Parameters
Adding a ?withParams=true
parameter to the endpoint will extend the response with details about procedure parameters:
- parameter name,
- parameter data type,
- parameter type (in, out, result set, etc)
POST http://<cdatavirtuality-server-address>:8080/rest/api/{source-name}/{procedure-name}?withParams=true
Request:
POST http://<cdatavirtuality-server-address>:8080/rest/api/SYSADMIN/md5?withParams=true
Body (application/json):
'{"param" : "please md5 it"}'
STATUS 200
[
{
"procParams": [
{
"Name": "param",
"DataType": "string",
"Type": "In"
},
{
"Name": "hash",
"DataType": "string",
"Type": "Out"
}
]
},
{
"hash": "4BC3338E788464C21918D09A64AB6212"
}
]
Response parameters are available since v4.0.7
Response Format
The response can be requested in the following formats:
- JSON
- XML
- Array
The required format can be set by either the ACCEPT
header or the format
parameter. Use application/json
, application/xml
or application/array
as the ACCEPT
header values or json
, xml
or array
as the format
parameter values.
Response format available since v4.5