I'm facing an issue with using $resource for making a post request in my app.
Here is the code snippet from my Angular module:
angular.module('myApp').factory('Product', ['$resource',
function ($resource) {
return $resource( '/api/product/:id', {
id: '@id'
}, {
'save': {
method: 'POST',
isArray: true,
url: '/api/product/:id/addProduct'
//a different URL for adding a product.
,}
}
);
}
]);
And here's how I'm calling it in my controller:
Product.save({
name:'test name',
quantity:'5'
})
The issue arises when the request is made without an ID:
/api/product/addProduct //no ID provided
However, if I include an ID:
Product.save({
id:'12345',
name:'test name',
quantity:'5'
})
The request URL is correct /api/product/12345/addProduct
but the payload includes the ID parameter:
id:'12345',
name:'test name',
quantity:'5'
The server cannot process the ID as part of the payload. I'm unsure how to solve this issue. Any ideas on how to properly make the POST request? Appreciate any help! Thank you!