Allow fullRequestInterceptor to modify path
My backend handles GET requests of the form /users/123/accounts to get all accounts from user 123, but to update one of those accounts, one would use PUT /accounts/456 as opposed to PUT /users/123/accounts/456. Rather than explicitly setting acct.parentResource = undefined every time I want to do a non-GET RESTful operation in my application, it would be nice if I could do this once, when configuring Restangular, by using the fullRequestInterceptor to set element.parentResource=undefined for all non-GET requests.
For this to work, however, either fullRequestInterceptor needs to be called before urlHandler.fetchUrl (in elemFunction), so that it can return a cloned object with no parentResource, or fullRequestInterceptor needs to be able to override the url somehow, presumably using urlHandler.
(Or am I missing something obvious here?)
Hey,
You can use parentless requests for those :).
https://github.com/mgonto/restangular#setparentless
If you set parentless to accounts, it'd mean that after you got it, put, delete and all other interactions would actually be used using base URL.
Hope this works :).
Otherwise, please reopen!
Unfortunately this seems to apply universally regardless of http method. My backend in question does use /users/123/accounts to get a list of all accounts for user 123, whereas /accounts would simply be a list of all accounts for all users. So, parentless won't work, unless I can set it before any PUT or DELETE, and clear it before any POST (e.g., POST /users/123/accounts would add a new account to user 123) or GET. Also, unless I'm mistaken, it's not possible to call setParentless in a request interceptor anyway, and have it make a difference, because by then the request path is already built.
Basically, it's too coarse-grained for my needs. Mind you I can accept that perhaps in my case it's not Restangular's responsibility to support this sort of backend semantics, but it would be nice.
I understand.
Any suggestions on how you'd configure it or you'd do it?