Restangular – get root collection

Issue

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 🙂

Solution

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();

Answered By – Huy Chau

Answer Checked By – Senaida (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.