$resource POST not adding trailing slash

1,888 views
Skip to first unread message

Matias

unread,
May 26, 2012, 2:51:57 PM5/26/12
to ang...@googlegroups.com
I have a module where I define a service like this:

 .factory("Charts", function ($resource) {
        return $resource("/api/charts/:chartId", {
        }, {});
    })


Then, on the controller I do:

 var chart = new Charts({
                name:$scope.name,
                query:$scope.query,
                since:$scope.since,
                since_unit:$scope.since_unit,
                interval:$scope.interval
            }
        );
        chart.$save();

And on the server I'm receiving the POST to /api/charts instead of /api/charts/ that is what (I think) it should be.

Am I missing something?

Thanks a lot for your help.


Dan Doyon

unread,
May 26, 2012, 3:05:09 PM5/26/12
to ang...@googlegroups.com
I encountered this just recently, and it may be causing me issues with django. I believe angular is stripping this off intentionally. Also, if you want your variables to come into the post part of request you should define parameter defaults like { 'name': '@name', 'query' : '@query etc ... }

dan


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/0WE-0QNoWwAJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Matias

unread,
May 27, 2012, 2:45:41 PM5/27/12
to ang...@googlegroups.com
I've just created an issue in github. Hope they at least can confirm if this is a bug or a feature :)



Thanks for your help!
To unsubscribe from this group, send email to angular+unsubscribe@googlegroups.com.

smace...@gmail.com

unread,
Jan 2, 2013, 6:39:47 PM1/2/13
to ang...@googlegroups.com
to test on jsfiddle you need the trailing slash for echo/json/ are there any workarounds or is there any plans to allow this? i noticed something about the future of resources is uncertain... is this something that is going to loose support? i think it pairs very nicely with the restfull service by fuelphp fo create a very abstract and powerful solution.

Johannes Hiemer

unread,
Jan 3, 2013, 4:18:23 AM1/3/13
to ang...@googlegroups.com, smace...@gmail.com
Hi guys,
I was experiencing the same behavior, but normally this kind of notation is valid. What should be added is the option to activate trailing slashes.

Are you not able to modify your server side mapping?

Andrew Schmaltz

unread,
Jan 29, 2013, 12:37:21 PM1/29/13
to ang...@googlegroups.com, smace...@gmail.com
I can change MY server side mapping, but I can't change other people's (like my example of jsfiddle).

joshkurz

unread,
Mar 1, 2013, 5:00:43 PM3/1/13
to ang...@googlegroups.com
Has there been any update on this issue? Is there a setting to force resource to allow for the appending slash? There are many api's that consider the trailing slash best practice. 

Arsen Kuntic

unread,
Mar 4, 2013, 6:25:29 AM3/4/13
to ang...@googlegroups.com
The only alternative is using $http or creating your own custom 'resource' wrapper as far as I know.

While I think no-slash is a better practice, $resource should definitely be more flexible in this regard.


Arsen.

Paullus Nava

unread,
Jun 5, 2013, 9:50:41 PM6/5/13
to ang...@googlegroups.com
Hello guys, I was facing the same issue with angular 1.1.4...

In a urgency I made these modifications:
- Opened file angular-resource.js and removed the code ".replace(/\/*$/, '')" on line 363| - Modified my resources to have double trailing slash like below:

var myApp = angular.module('usuarios', ['ngResource'])
.factory('Usuario', function($resource){
var actions = {
'edit':    { method:'PUT' }
};
return  $resource('/app/usuario/:id//', {id:'@id'}, actions);
})


After those changes it worked for me... quite ugly, I agree, but I need this system to be operating tomorrow and had no time to change all my code to $http... if anyone is in the same situation, this workaround can be useful.

Philip Adzanoukpe

unread,
Feb 20, 2014, 6:58:51 PM2/20/14
to ang...@googlegroups.com
Hi guys,
I had the same issue when working on django, but adding slash and space at the end worked for me.

$resource('/api/charts/:chartId/ ");
Reply all
Reply to author
Forward
0 new messages