Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Services call stacks

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

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.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Services call stacks

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×