I'm using Angular's $resource service to make calls to a RESTful web service. Currently I'm doing this:
app.factory('data', function($resource) {
// Creating resource objects for all resources I have.
var usersResource = $resource('http://example.com/api/users/:id', {id: '@id'});
var universitiesResource = $resource('http://example.com/api/universities/:id', {id: '@id'});
// ..
// Initializing more resource objects.
return {
users: {
getAll: function() {
return usersResource.query();
}
// ..
// More methods..
},
universities: {
getAll: function() {
return universitiesResource.query();
}
// ..
// More methods..
}
// ..
// More objects.
}
});
The other way is to have a different data factory for every resource. So, my question is what's the proper way of doing this and why? It looks more structured to have just a single data factory, but are all these resource objects making a lot of burden and reducing the performance of the app?