Q:

AngularJS changes the url depending on method (Get, Put)

I'm using factories in Angular to bind ajax requests to my web api. The factory looks like this.
app.factory('QuestionContainer', ['$resource', function ($resource) {
return $resource('http://localhost:52133/api/questioncontainerapi/:id', null,
    {
        'update': { method: 'PUT' },
        'publish': { method: 'Put', url: 'http://localhost:52133/api/questioncontainerapi/:id/Publish/' }
    });
}]);

As you can see I've put :id between two actions in the url and the method is currently Put. If I in my controller use the factory like this ->
QuestionContainer.publish({ id: 1 });

the request url beocmes http://localhost:52133/api/questioncontainerapi/Publish/ with a body of { id: 1 }. If I instead use the Get method the request url changes to http://localhost:52133/api/questioncontainerapi/1/Publish/, this is the url I want.
How can I make Angular understand this?
Thanks!

A:

You need to specify the param, try with the following code:
app.factory('QuestionContainer', ['$resource', function ($resource) {
return $resource('http://localhost:52133/api/questioncontainerapi/:id', {id: '@id'},
    {
        'update': { method: 'PUT' },
        'publish': { method: 'Put', url: 'http://localhost:52133/api/questioncontainerapi/:id/Publish/' }
    });
}]);

jsfiddle
in console you can see the requests
Explanation
url: /some/:param
Param must be defined, so we say {param: 'text'}, in this case the url would be resolve to /some/text always..
But if we want to have dynamic urls based on variables we specify:{param: '@p'}
Where p is a variable that belongs to the instance resource or to the data object you pass to a class resource.
QuestionContainer.publish({ id: 1 }); // {id: 1} is the data object

So if we want the /some/3 we do it like the following:
QuestionContainer.publish({ p: 3 }); // class
var question = new QuestionContainer({p: 3}); // or new QuestionContainer(); question.p = 3;
question.$publish();

The official page could extend more in this: $resource

