0

I want to configure an angular $resource. This $resource should allows to call distant web services.

// Gets all the nested-resources of a parent-resource
1) GET  /parent-resource/nested-resources
// Gets a nested-resource by id
2) GET  /nested-resource/{id}
// Create a nested resource
3) POST /nested-resource

In my scenario, i want retrieve all the nested resources using the first web service. When a nested resource is modified by the user, the nested resource will be save using the third web service.

var NestedResource = $resource('/nested-resource/:id');
Publishable.prototype.isNew = function() {
    return this.id === undefined;
};
... lot of functions...

This configuration works well to hit the 2nd and 3rd web services but how can i configure the resource to use the 1st. Several functions are register on the nested resource prototype, i would like to avoid the creation of a specific $resource.

Publishable.prototype.getByParentId = function(parentId) {
    // ??        
}

1 Answer 1

1

Create a custom action on the resource as follows:

var NestedResource = $resource('/nested-resource/:id',,
    { action: "getAll",
      method: "GET",
      isArray: true,
      url: '/parent-resource/:parentId/nested-resources'
    });

Now you should be able to do:

var allItems = NestedResource.getAll({parentId: 1});

to retrieve the list for parentId 1.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. how i specify the parent resource id ?
see my update - I'm not sure I understand your question now, but hopefully that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.