-
Notifications
You must be signed in to change notification settings - Fork 2
3.1) Create
Guido Barbaglia edited this page May 27, 2015
·
13 revisions
The service can be consumed through a POST call to WDS and it is possible to create multiple rows/documents at once.
This parameter is used to specify the name of the collection, for MongoDB and OrientDB databases, or the name of the table, for SQL databases. New resources will be created in the specified collection/table.
The payload is the same for every DBMS and it consists of an array of objects. In the case of SQL each object is converted in a INSERT statement.
{
"query": [
{
"name": "Mouse",
"price": 9.99,
"items": 3
},
{
"name": "Keyboard",
"price": 19.99,
"items": 5
}
]
}The output is an array of objects. Each object contains the ID of the new resource that has been created.
[
{"id":"556480d9e4b0d1ecc4c8332a"},
{"id":"556480d9e4b0d1ecc4c8332b"}
]In the case of SQL databases, where no default ID exists, the output return the number of lines that have been created.
[
{"id":"1 rows have been added."},
{"id":"1 rows have been added."}
]$.ajax({
type: 'POST',
url: 'rest/crud',
data: {
payload: {
"query": [
{
"name": "Mouse",
"price": 9.99,
"items": 3
},
{
"name": "Keyboard",
"price": 19.99,
"items": 5
}
]
},
datasource: "my_datasource",
collection: "my_collection",
outputType: "object"
},
success: function (response) {
/* Do something with the output... */
},
error: function (a) {
alert(a.responseText);
}
});