restangular multiple api sources

Issue

I can set one api provider per angularjs app for restangular like this

    RestangularProvider.setBaseUrl('http://localhost:8080/api');

but how do i setup multiple base url’s and use them selectively.
I want to configure and use both of below end points

      RestangularProvider.setBaseUrl('http://localhost:8080/api');

      RestangularProvider.setBaseUrl('http://localhost:8090/apiws');

how do I do it with Restangular?

Solution

It’s found in the docs

factory("service1", ["Restangular", function(restangular) {
  return restangular.withConfig(function(RestangularConfigurer) {

    RestangularConfigurer.setBaseUrl("http://localhost:8090/apiws");

  });

}]);


factory("service2", ["Restangular", function(restangular) {
  return restangular.withConfig(function(RestangularConfigurer) {

    RestangularConfigurer.setBaseUrl("http://localhost:8080/api");
    RestangularConfigurer.setDefaultHeaders({
      "Authorization": "Basic 123345667",
    });

  });

}]);

Answered By – wayne

Answer Checked By – Pedro (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.