Can you build a URL in Restangular with multiple variables?

Issue

I am trying to build a resource in Restangular with a URL that has multiple variables. The server variable is set, so I need to figure out how to do this client side.

This is the URL that I was using in ngResource:

'/api/v1/reports/shipped-orders/:reportDate/:orderType'

There isn’t really any nesting past shipped-orders, it’s just passing parameters through the URL.

I tried chaining them like:

_reports.one('shipped-order', '2013-11-04').one('', 'bulk')

But that turned out a url with double slashes in it.

Solution

I recently ran into this problem. Here’s what I did:

myApp.factory('myRestService', ['Restangular', function(Restangular) {
    return {
        myFunction: function(varA, varB, varC) {
            var path = "rest/primaryPath/" + varA + "/" + varB + "/" + varC;
            var restObject = Restangular.all(path);
            var thePromise = restObject.getList();

            return thePromise;
        }
    };
}]);

By building the path myself, I was successfully able to use more than one variable and get a result from the Java Rest Service I was using in my project.

Answered By – C1pher

Answer Checked By – Marilyn (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.