Services call stacks
Problem
I have writen a huge amount of backbone.js models, collections and most of them content RESTful service calls using URL.
How can i make these URL service calls as Central Hub, where all the urls are added and all the models / collections refer this central hub for their RESTful calls.
Problem courtesy of: Ashwin Hegde
Related Articles
Solution
I used a specific model for settings on a recent project and stored the data in an external json file.
JSON:
{
"service-1": "http://url.to.service-1",
"service-2": "http://url.to.service-2"
}
SettingsModel:
var SettingsModel = Backbone.Model.extend({
url: 'scripts/data/settings.json'
});
Usage:
var settings = new SettingsModel();
settings.fetch({
success: function() {
var model = new MyModel({ url: this.get('service-1') });
}
});
Solution courtesy of: net.uk.sweet
Discussion
View additional discussion.