Search
Learn
Share

New restdb.io JavaScript API makes databases more fun for webdevs

restdb.io can now autogenerate a complete JavaScript API* for your database. This makes it easy for developers to create web applications with dynamic content. The API also ensures that your code follows the schema for your database.

The following example uses the "rdb-simpledb" database to create an API for that database. Include this script in the head of your html page (replacing the database name with your own):

<script src="https://rdb-simpledb.restdb.io/rest/_jsapi.js?apikey=<your-api-key>">

When the auto generated JavaScript is loaded, you can connect to your database. This is done by creating a new instance of the restdb.io api and assign it to a variable:

var db = new restdb("https://rdb-simpledb.restdb.io", "<your-api-key>");

Query some data records from the "products" collection:

var query = {}; // all
var hint = {"$max": 10}; // first 10 only
db.product.find(query, hint, function(err, productlist){
// productlist is an array of product objects ...
}

Creating a new object and saving it to the database is just as simple:

var p = new db.product({name: "from jsapi"});
p.save();

Getting and deleting stuff is also easy:

var p = db.product.getById("5662d2d7632700720000008c");
p.delete();

Blog post