1

I am using Angularjs Chrome 35.0 and Firefox 30.0. I need to make Rest requests to an API. Some of those finishes by / like : http://mydomain.com/path/to/folder/

It won't work without this / and I don't have the hand on the API.

To do this I use un service using resource :

this.folder = function(folderKey) {
        var methods = resource(url, null, {
            'create': {
                method: 'PUT',
                url: config.domain + folderPath + '\\/'
            }
        });
        return methods;
    };

If I only put / or \/, angular doesn't keep the ending / while doing the request.

The '\\/' is the only way i found to keep it.

It does work well in chrome but in firefox it does make this url which obviously doesn't work : http://mydomain.com/path/to/folder%5C

BastienSander
  • 1,718
  • 4
  • 24
  • 50
  • The code here contains a range of syntax errors. Can you show some code which actually illustrates what you are doing to make the request? – chrisg Jul 15 '14 at 12:48
  • @chrisg : I forgot one line of code, added it. – BastienSander Jul 15 '14 at 12:49
  • 1
    That looks better thanks. It is a little strange that the server is that sensitive to having a trailing `/` on the URL, but I guess you can't change that. Does it help to put a `/.` on the end of the URL? I wonder whether that would make the browser send through what you need, and whether the server will handle that to do the create action as desired. – chrisg Jul 15 '14 at 13:06
  • what happens when trailing `/` left off at API? Seems unusual to need one. If you control the API would be simpler to fix at server if it is causing problems – charlietfl Jul 15 '14 at 13:06
  • It won't work without this `/` and I don't have the hand on the API. – BastienSander Jul 15 '14 at 13:14
  • @chrisg : with a `.` at the end, firefox sends : `http://mydomain.com/path/to/folder%5C\` and so it work with `url: config.domain + folderPath + '\/.'`. – BastienSander Jul 15 '14 at 13:17
  • Apparently it also work with chrome ! – BastienSander Jul 15 '14 at 13:18
  • @chrisg, you can post the answer I will accept it, it does work well. – BastienSander Jul 15 '14 at 13:21
  • Thanks for confirming. – chrisg Jul 15 '14 at 13:25

3 Answers3

1

Putting a . at the end of the URL will avoid the trailing \ from being trimmed. Whether this will work in general will obviously depend on how the server handles the ., but if you have a server that does what you want then it should help.

chrisg
  • 1,117
  • 8
  • 8
0

I agree with the comments above that the web service should not be sensitive to the trailing slash in url.

But if you really want to turn off the auto stripTrailingSlashes behaviour, you can pass the option like this:

this.folder = function(folderKey) {
    var methods = resource(url, null, {
        'create': {
            method: 'PUT',
            url: config.domain + folderPath + '\\/'
        }
    }, {
        stripTrailingSlashes: false
    });
    return methods;
};

Edit: this feature is available since angular v1.3.0-beta.6 which is still in an unstable state.

runTarm
  • 11,537
  • 1
  • 37
  • 37
0

According to

Recommended way of getting data from the server

it seems that people recommend the use of $http instead of ressource for that kind of url.

Community
  • 1
  • 1
BastienSander
  • 1,718
  • 4
  • 24
  • 50