Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need feature to append trailing slash #90

Closed
jaywhy13 opened this issue Jun 5, 2013 · 14 comments
Closed

Need feature to append trailing slash #90

jaywhy13 opened this issue Jun 5, 2013 · 14 comments
Assignees
Labels

Comments

@jaywhy13
Copy link

jaywhy13 commented Jun 5, 2013

This a great API, just wish it didn't suffer the same fate as AngularJS where Angular strips the trailing slash without asking permission :(

@mgonto
Copy link
Owner

mgonto commented Jun 5, 2013

Hey,

Have you tried escaping it? Using it like \\/?

Could you give me a plunkr example of this not working?

Thanks!!!

@ghost ghost assigned mgonto Jun 5, 2013
@mgonto
Copy link
Owner

mgonto commented Jun 5, 2013

Maybe you can check out:

#54

He's got it working.

@jaywhy13
Copy link
Author

jaywhy13 commented Jun 5, 2013

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.

@mgonto
Copy link
Owner

mgonto commented Jun 5, 2013

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!!

@cellofellow
Copy link

Here's my Plunk. It shows Firefox's behavior (use Firefox) http://www.plnkr.co/edit/yWt9124hXdyODCLKsXF0

@mgonto
Copy link
Owner

mgonto commented Jun 6, 2013

Hey, it doesn't work on Firefox, but it does in chrome. It's pretty weird.

@mgonto
Copy link
Owner

mgonto commented Jun 6, 2013

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.

@mgonto
Copy link
Owner

mgonto commented Jun 6, 2013

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

@jaywhy13
Copy link
Author

jaywhy13 commented Jun 6, 2013

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 (angular/angular.js#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.

@mgonto
Copy link
Owner

mgonto commented Jun 6, 2013

Closing this one. I'm gonna implement this on #97

@mgonto mgonto closed this as completed Jun 6, 2013
@mgonto
Copy link
Owner

mgonto commented Jun 20, 2013

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

@jaywhy13
Copy link
Author

Will certainly test and let you know.
On Jun 19, 2013 11:58 PM, "Martin Gontovnikas" notifications@github.com
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//issues/90#issuecomment-19730971
.

@abulte
Copy link

abulte commented Sep 23, 2013

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)

@Putr
Copy link

Putr commented Feb 3, 2016

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/?

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

No branches or pull requests

5 participants