Applications manipulate data in a restdb.io database with REST verbs over the HTTP protocol.
The generic format for manipulating data in a database is:
VERB
https://<db-name>.restdb.io/rest/<collection>/[ID][<subcollection>/SUBID][?params...]
The following sections documents how you can create, update and delete data in your database.
Creates a new record / document in a database collection.
Example:
POST
https://<dbname>.restdb.io/rest/blog
{
"title": "Welcome to the blog post",
"comments": [],
"followers": 1
}
Results in this document:
{
"_id": "588f439418f328ec5e024277",
"title": "Welcome to the blog post",
"comments": [],
"followers": 1,
"_created": "2017-03-28T12:32:19.069Z",
"_changed": "2017-03-28T12:32:19.069Z",
"_createdby": "api",
"_changedby": "api"
}
Updates an existing record / document in a database collection.
Example:
PUT
https://<dbname>.restdb.io/rest/blog/588f439418f328ec5e024277
{
"title": "Here we go with the blog",
"followers": 1,
"comments": []
}
Increase or decrease a field value on an existing record / document.
Example:
PUT
https://<dbname>.restdb.io/rest/blog/588f439418f328ec5e024277
{"$inc": {"followers": 1}}
The increment value must be a part of the request body document. The value to increment must be an integer. Use negative values to decrement field.
Append an element to a sub array on an existing record / document.
Example:
PUT
https://<dbname>.restdb.io/rest/blog/588f439418f328ec5e024277
{"$push": {"comments": "This is a comment to a blog post."}}
Results in this document:
{
"_id": "588f439418f328ec5e024277",
"title": "Welcome to the blog post",
"comments": [
"This is a comment to a blog post."
]
}
Remove an element from a sub array on an existing record / document.
Example:
PUT
https://<dbname>.restdb.io/rest/blog/588f439418f328ec5e024277
{"$pull": {"comments": "This is a comment to a blog post."}}
Update one or more properties on an existing record / document in a database collection.
PATCH
https://<dbname>.restdb.io/rest/blog/588f439418f328ec5e024277
{"title": "A patched title"}
You can also use the $inc, $push and $pull operators with a PATCH verb.
Delete an existing record / document from a database collection.
Example:
DELETE
https://<dbname>.restdb.io/rest/blog/588f439418f328ec5e024277
Results from the operation:
{
"result": [
"588f439418f328ec5e024277"
]
}
Delete many records documents from a database collection. The number of deleted records are based on the query, e.g. to delete all records add q={}
.
Important: Only allowed with a full access API-key or from a Codehook.
Example:
DELETE
https://<dbname>.restdb.io/rest/blog/*?q={"name": "Jimmy"}
Result from operation:
{
"result": 1
}
For more advanced behaviour and data manipulation, read about Codehooks.