Kindzoku Kindzoku - 5 months ago 25
AngularJS Question

Restangular - get root collection

I'm trying to implement Restangular in my SPA application.
I have multiple API root addresses.

So I created base providers (factories) for each API root, for example:

function ApiUsers(Restangular){
return Restangular.withConfig(function(config) {
config.setBaseUrl('/srv/users');
});
}


Where /srv/users returns all users.
So my question is - how i can query root? I mean, I want to do something like:

return ApiUsers.getList();


or

return ApiUsers.all().getList();


But nothing seems to work... :(

Thx in advance :)

Answer

Your app.config.js:

'use strict';

var appConfig = function (RestangularProvider) {

  var serverID = 'http://domain.com'; // sample 

  // Set default api
  RestangularProvider.setBaseUrl(serverID + '/srv/users');

};

appConfig.$inject = [
  'RestangularProvider'
];

users.api.js:

return Restangular.all('').getList();
Comments