In 'Backbone.Collection' should I Use 'Backend:' or 'URL:'?
1manStartup opened this issue · comments
So im trying to connect my Database created JSON REST API to Backbone.IO.
- Normally a Backbone Collection would be like this...
Messages = Backbone.Collection.extend({
model: Message,
url: '/api/messages'
});
- But I notice that Backbone.IO uses a 'backend' property. Am I supposed to add 'backend' with 'url' like so (The goal is to use with my api)?
var Messages = Backbone.Collection.extend({
// Specify the backend with which to sync
backend: 'messages',
//URL from API here
url: '/api/messages',
model: Message,
initialize: function() {
// Setup default backend bindings
// (see lib/browser.js for details).
this.bindBackend();
}
});
Thanks.
The url
is for syncing data via AJAX requests. When backend
is specified, Backbone.IO overrides the default implementation of Backbone.sync
to sync models over a Socket.IO connection. If you have a REST API but want to push updates to the client I would recommend something lower-level like https://github.com/logicalparadox/backbone.iobind or just plain Socket.IO. If you're just trying to push updates from the server and use AJAX for all CRUD operations I usually prefer something simpler like server-sent events (http://www.html5rocks.com/en/tutorials/eventsource/basics/).
Got it, will check those out. Thanks.