Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Conversation

guillaume86
Copy link

This change adds the possibility to overridde the template URL when creating $resource custom actions:

var Person = $resource('/Person/:id', {}, {
  clear: { method: 'POST', url: 'Person/clear' }
});

Person.clear(); // POST /Person/clear

Add the ability to override the URL used in $resource custom actions.
Add test for URL overriding in $resource actions.
@BrynCooke
Copy link

I would really like to see this happen as it is impossible to work with some rest services at the moment without creating several resources.

I note that the pull request conflicts with master now, I have fixed it on my branch, shall I submit another pull request?

@nolazybits
Copy link
Contributor

Same here... It's nice to have the resource with one URI and default CRUD but if you want to push it a little further it gets annoying. Would love to have this functionality also...
Any idea when this will be merged in the main repo?
Cheers

@nolazybits
Copy link
Contributor

@BrynCooke I'm trying to use your fork and I have a question. Does the binding between the url parameters and the object properties work?
ie if I have

return $resource( '', {},
{
get: { method:'GET', isArray: true, url:'user/:userId'},
}

and I call it like myResource.get({userId:1}), looking at charles I see the request being
/user/:userId?userId=1

Cheers,
Xavier

@nolazybits
Copy link
Contributor

@BrynCooke
Ok just forked angularjs branch and added this feature (heavily inspired by the mods you had done in your fork)
https://github.com/zeflasher/angular.js

Cheers

@nolazybits
Copy link
Contributor

Kindof hijacking the discussion here but done a PR (#2054) to address the above issue (heavily base on @BrynCooke code).
Cheers

@IgorMinar
Copy link
Contributor

@zeflasher I guess you meant @guillaume86's code ;-)

I'm going to close this PR as #2054 is more generic and handles this use case as well. Thanks @guillaume86 for your contribution!

@IgorMinar IgorMinar closed this Feb 24, 2013
@nolazybits
Copy link
Contributor

Ooops, my bad... Indeed Guillaume86's code...

@guillaume86
Copy link
Author

No problem

@elaleprieto
Copy link

¡this is great!

¡must be in the next release!

👍

:)

@FlyersWeb
Copy link

Hi,
I'm using v1.0.2 from Google CDN. I wanted to know if this feature is integrated in this version or not ?
Thanks.

@worldspawn
Copy link

It'd be sweet(er) if we could prefix the url with a magic token that prepends the resource base url to the new url so it doesn't need to be typed out over and over. So

var Person = $resource('/Person/:id', {}, {
  clear: { method: 'POST', url: 'Person/clear' }
});

might become

var Person = $resource('/Person/:id', {}, {
  clear: { method: 'POST', url: '@/clear' }
});

Not sure if it matters that :id would be prepended. I think as long as there was no id provided to the call it will be stripped from the url.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants