I have implemented Angular factories to connect ajax requests with my web api. Below is an example of how the factory is structured.
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/' }
});
}]);
You can observe that I have inserted :id
between two actions in the URL and the current method specified is Put
. When using the factory in the controller as follows ->
QuestionContainer.publish({ id: 1 });
the request URL becomes
http://localhost:52133/api/questioncontainerapi/Publish/
with a body of { id: 1 }
. If I switch to the Get
method, the request URL changes to http://localhost:52133/api/questioncontainerapi/1/Publish/
, which is the desired URL.
How do I configure Angular to achieve this behavior? Appreciate any guidance!