OData Operations
OData Operations
After connecting to CData Connect Cloud virtual datasets using OData, you can execute create, read, update, and delete (CRUD) operations. The availability of these operations can vary between data sources.
You can execute CRUD operations through GET, POST, PATCH, and DELETE requests, which are outlined below. Results from requests are returned in JSON format. See Query Options for information about refining and filtering requests.
GET
An HTTP GET request retrieves a record or a set of records from the server. The following request retrieves all of the records in the Cars table:
GET https://cloud.cdata.com/api/odata/{workspace_name}/Cars
Here is the corresponding response:
{
"@odata.context": "https://cloud.cdata.com/api/odata/{workspace_name}/$metadata#Cars",
"value": [
{ "Id": "1", "Color": "Color_1", "Model": "Model_1"},
{ "Id": "2", "Color": "Color_2", "Model": "Model_2"},
{ "Id": "3", "Color": "Color_3", "Model": "Model_3"}
]
}
POST
An HTTP POST request creates a new record in an entity. The request must contain the inputs required to create the record. The following example request creates a new record in the Cars table:
POST https://cloud.cdata.com/api/odata/{workspace_name}/Cars
{
"Color": "Color_4", "Model": "Model_4"
}
Here is the corresponding response:
{
"@odata.context":"https://cloud.cdata.com/api/odata/{workspace_name}/$metadata#Cars",
"value":[
{
"Id": "4",
"Color": "Color_4",
"Model": "Model_4"
}
]
}
PATCH
An HTTP PATCH request updates a record. You must provide the primary key for the record in the header of the request.
The following example edits the record created with the POST request above. The Id of that record is 4, which is passed in the header. The request updates the values of Color and Model:
PATCH https://cloud.cdata.com/api/odata/{workspace_name}/Cars('4')
{
"Color": "Color_10",
"Model": "Model_10"
}
Here is the corresponding response:
{
"@odata.context":"https://cloud.cdata.com/api/odata/{workspace_name}/$metadata#Cars/$entity",
"Id": "4",
"Color": "Color_10",
"Model": "Model_10"
}
DELETE
An HTTP DELETE request deletes a record. You must provide the primary key for the record in the header of the request.
The following example deletes the record that was created and modified above:
DELETE https://cloud.cdata.com/api/odata/{workspace_name}/Cars/('4')
Here is the corresponding response:
{
"@odata.context": "https://cloud.cdata.com/api/odata/{workspace_name}/$metadata#Cars('4')"
}