-
Notifications
You must be signed in to change notification settings - Fork 9
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);