Skip to content
This repository was archived by the owner on Nov 27, 2018. It is now read-only.

Creating a RESTful data store

Jason Mulligan edited this page May 8, 2013 · 10 revisions

Creating a RESTful data store

Please read Creating a data store before continuing.

A RESTful data store abstracts API interaction automatically for you "behind the scene". Being RESTful implies being part of the feedback loop, so if you create, update or delete a record it will be reconciled with the Server before the local representation reflects the change.

The API end point under a collection will become the key of the local record, e.g. http://api.yourdomain.com/users/123 is record 123; the users collection would be a child data store , accessible via app.data.get("users");

Recursive API crawling can be initiated by setting data.retrieve & data.recursive to true.

When you make a data store RESTful, you can explicitly expire the data via data.setExpires.

You can "ping" a data store to see if it's "ready" by checking the data.loaded boolean.

(function ($) {
var app = $.data({id: "app"}, null, {key: "name"}),
    uri = "http://api.yourdomain.com";

app.data.setUri(uri).then(function (recs) {
	// Data is loaded
	
}, function (e) {
	// Something went wrong
	
});

app.data.setExpires(5 * 60 * 1000); // data is valid for 5 minutes
})(abaaso);

Clone this wiki locally