Search code examples
angularjsrestangularhttp-delete

RESTAngular - DELETE, not working as it should


If i am not mistaken in RESTful services in order to remove a record you need to do this:

Delete a product: DELETE /api/product/id (reference)

But in RESTAngular when i do for example

product.remove();

A DELETE request is made to /api/product whith the whole product object in the Requests Body. This is not what i want!

Here is my code:

myApp.factory('RESTService', [ 'Restangular', function (Restangular) {
    var restAngular = Restangular.withConfig(function (Configurer) {
        Configurer.setBaseUrl('/myAPI/');
    });
    var service = {};
    service.Product= restAngular.service('product');
    return service;
}]);

GET one Product

RESTService.Product.one(id).get().then(function (response) {
    $scope.product= response;
})

DELETE the Product

$scope.product.remove();

I want when i do product.remove() to send a DELETE Request to /myAPI/product/id. How can i do that?


Solution

  • // DELETE /accounts/123/buildings/456
    Restangular.one("accounts", 123).one("buildings", 456).remove();