Documentation

Learn how to create databases and use the REST API.

Visit the blog for in-depth articles and tutorials.

Join our FB group to interact with the restdb.io team and active users.


Data manipulation with REST

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.

POST

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"
}

PUT

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": []
}

The $inc operator

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.

The $push operator

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."
  ]
}

The $pull operator

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."}}

PATCH

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

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 by Query

Delete many records documents from a database collection. Important: Only allowed with a full access API-key or from a Codehook.

Example:

DELETE
https://<dbname>.restdb.io/rest/blog/*?q={"status": "purge"}

Result from operation:

{
  "result": 1
}

For more advanced behaviour and data manipulation, read about Codehooks.