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: {
...
}
}),
}
}]);
Am I doing it wrong or is what I'm asking just not doable?