3

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?

Christos Baziotis
  • 5,845
  • 16
  • 59
  • 80

2 Answers2

4
// DELETE /accounts/123/buildings/456
Restangular.one("accounts", 123).one("buildings", 456).remove();
Nidhish Krishnan
  • 20,593
  • 6
  • 63
  • 76
Archana
  • 387
  • 1
  • 5
-1

You can delete a record using RESTFul($http) Service like this

$http.delete('/myAPI/product' + id, {params: {id: id}});
Nidhish Krishnan
  • 20,593
  • 6
  • 63
  • 76
Archana
  • 387
  • 1
  • 5