I'm using an AngularJS $resource factory to access a client REST services. Some of the parameters are defined with optional path parameters rather than query parameters.
Case 1:
I call myUrl/application-:applicationID/limit-:limit.json
with:
{
applicationID:"1234",
limit: 10
}
I get the correct URL of myUrl/application-1234/limit-10.json
Case 2:
I call myUrl/application-:applicationID/limit-:limit.json
with:
{
applicationID:"1234"
}
I want the resulting url to ignore the optional limit
parameter and collapse down to myUrl/application-1234.json
However, what I get is myUrl/application-1234/limit-.json
*EDIT I have several API categories eg Foo1, Foo2, and each has several endpoints eg endPoint1, endPoint2 and using the method in @Deiter's post, I can't see a way to cleanly list all my resources without using temporary category names then binding them all together at the end.
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: {
...
}
}),
}
}]);
Example call:
MyAPI.Foo1.endPoint1 ( { application: "1", limit: 5 } );
MyAPI.Foo2.endPoint2 ( { application: "1" } );