Need feature to append trailing slash
This a great API, just wish it didn't suffer the same fate as AngularJS where Angular strips the trailing slash without asking permission :(
Hey,
Have you tried escaping it? Using it like \\/?
Could you give me a plunkr example of this not working?
Thanks!!!
Maybe you can check out:
https://github.com/mgonto/restangular/issues/54
He's got it working.
The thing is that with Django, we need the trailing slash. I had a read of #54 and I've actually worked around mine by doing something like Restangular.one("customer").post({...}).then(...). In Django, we can tell it to append the trailing slash. This works fine for GET, since what it does it just simply redirect, however it doesn't work out for POST because with a POST redirect, the data is lost.
I forked your API and started doing some reading last night, I was thinking of trying to add a "alwaysAppendTrailingSlash" option or something of that sort. I think would help alot of Django users. I'm glad I came across your API because generally, from what I've seen on the web so far, people generally just end up building their own API for doing REST (instead of using $resource) because AngularJS doesn't ask your permission before stripping the trailing slash. Atleast with your API I could do the escaping easily.
I'll try something and do a pull request.
I've actually worked around mine by doing something like Restangular.one("customer").post({...}).then(...)
Hey, but with the setRequestSuffix('\\/') it should work perfectly and it shouldn't be removed by AngularJS.
Could you please provide me a http://plnkr.co/ example which shows this bug (How trailling slash is not send) so that I can reproduce this. If I can reproduce this, there's no need for sending a PR, I can take a look at fix it, but I think it should be working.
Thanks again!!
Here's my Plunk. It shows Firefox's behavior (use Firefox) http://www.plnkr.co/edit/yWt9124hXdyODCLKsXF0
Hey, it doesn't work on Firefox, but it does in chrome. It's pretty weird.
Hey, would this work?
/contacts/?
Because that can be easily set by just doing setRequestSuffix('/?')
The problem is that this trailling slash removal is done in $resource. In order to fix this, I'd have to change the code and start using $http instead of $resource inside.
So, I've completely checked this out. It doesn't work on Firefox at all, except for that exception that I pointed there.
If that doesn't work, I'm going to create a ticket to change $resource to $http internally. That would fix these problems, as they're actually $resource bugs that I cannot fix without modifying Angular's code.
Please let me know and I'll create this issue otherwise. Maybe I should've used $http instead of $resource from the begining
Ok, weirdly enough I got some errors about Chrome not running the script because the MIME type was text and strict MIME type checking is enforced. As you said though, setRequestSuffix('\\/') doesn't work in Fox. It just throws a %5C at the end of the url for both GET and POST. When I tried it in my code, in Chrome it adds two slashes "//" for POST and GET. Using '/?' works but it adds two '??' for GET, so I know that's not the right solution either.
You may be better off using $http internally indeed, because $resource apparently only works nicely for API's that don't require the trailing slash. See this conversation on Stack Overflow (http://stackoverflow.com/questions/14533117/angular-trailing-slash-for-resource) and the issue opened in Angularjs repo (https://github.com/angular/angular.js/issues/992).
It would be awesome though if there was a feature like I mentioned to simply choose to always add the trailing slash, because adding the slash is really conditional.
Closing this one. I'm gonna implement this on #97
Hey,
Try version 0.8.7 as I've now ditched $resource and I'm using only $http. Any help tetsing this out is appreciated :D
Will certainly test and let you know. On Jun 19, 2013 11:58 PM, "Martin Gontovnikas" [email protected] wrote:
Hey,
Try version 0.8.7 as I've now ditched $resource and I'm using only $http. Any help tetsing this out is appreciated :D
— Reply to this email directly or view it on GitHubhttps://github.com/mgonto/restangular/issues/90#issuecomment-19730971 .
Hi,
For those passing by, I can confirm that it works in FF with the code:
RestangularProvider.setRequestSuffix('/');
(don't escape the / or you'll get a %5C at the end of the URL)
For anyone still struggling with this (as it's still in the 1.4 branch): just add a "?" to the end of your string.
From
/api/contacts/
to
/api/contacts/?