I am currently developing an AngularJS client application that will communicate with a REST server.
To handle the interaction between the client and server, I have decided to use the $resource abstraction from AngularJS. Each resource is being written as a separate service and then injected into the specific controllers that require them.
Initially, I started off using the angularjs-seed template. As a result, my services.js file now contains a growing number of services:
angular.module('testReqService', ['ngResource']).
factory('TestReq', function($resource){
return $resource('http://test-url.com/api/test', {}, {});
});
angular.module('registerService', ['ngResource']).
factory('Register', function($resource){
return $resource('http://test-url.com/api/user/new', {}, {});
});
// More services are added here...
While everything seems to be functioning properly, I am questioning whether this is the most optimal approach.
My dilemma lies in whether it is better to create separate services for each individual REST request and only inject them into specific controllers, or if it would be more advantageous to create a single service with different methods and URLs for various requests?