I have multiple URL paths that I would like to map to a single resource. However I am unsure how to change the URL based on the function called. For example the :dest mapping for query would be /allProducts, however destroy would be something along the lines of /delete/:id
service.factory('ProductsRest', ['$resource', function ($resource) {
return $resource('service/products/:dest', {}, {
query: {method: 'GET', params: {}, isArray: true },
save: {method: 'POST'},
show: { method: 'GET'},
edit: { method: 'GET'},
update: { method: 'PUT'},
destroy: { method: 'DELETE' }
});
}]);
For each action you can override the url argument.
Specially for this is the url: {...}
argument.
In your example:
service.factory('ProductsRest', ['$resource', function ($resource) {
return $resource('service/products/', {}, {
query: {method: 'GET', params: {}, isArray: true },
save: {method: 'POST', url: 'service/products/modifyProduct'},
update: { method: 'PUT', url: 'service/products/modifyProduct'}
});
}]);
I just needed to put the url in as the param.
service.factory('ProductsRest', ['$resource', function ($resource) {
return $resource('service/products/:dest', {}, {
query: {method: 'GET', params: {dest:"allProducts"}, isArray: true },
save: {method: 'POST', params: {dest:"modifyProduct"}},
update: { method: 'POST', params: {dest:"modifyProduct"}},
});
}]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With