I'm using an AngularJS $resource factory to access some existing REST 
services. Some of the parameters are defined with optional path parameters 
rather than query parameters.

Examples:

MyAPI.Foo1.endPoint2 ( { application: "1234", limit: 5 } ); 
MyAPI.Foo1.endPoint2 ( { application: "1234" } ); 


What I want is to be able to use the same resource with optional parameters 
eg I want the resulting url to ignore the optional limit parameter if it's 
not specified and collapse down to "myUrl/application-1234.json".  However, 
what I get in the second example is "myUrl/application-1234/limit-.json".

I have several API categories eg Foo1, Foo2, and each has several endpoints 
eg endPoint1, endPoint2,

MyServices.factory ( 'MyAPI', ['$resource',

function ( $resource ) {

    return {

    Foo1: $resource ( '', 
    {                       
        application: "@applicationID",
        limit: "@limit"
    }, 
    {           
        endPoint1: {
            ...
        },
        endPoint2: { 
            url: "myURL/application-:applicationID/limit-:limit.json",
            method:'GET', 
            isArray:true
        },
    }),     

    Foo2: $resource ( '', 
    {                       
        application: "@applicationID"
    }, 
    {           
        endPoint1: { 
            ...
        },
        endPoint2: { 
            ...
        }
    }),             
}               
}]);    


I've tried the method detailed on this StackOverflow post 
[http://stackoverflow.com/questions/10382337/optional-url-parameters-in-angularjs-resource]
 
but I simply can't get it to work where both the following examples give 
the correct url.  

Am I doing it wrong or is what I'm asking just not doable?

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to