Search code examples
restangular

Restangular, is it possible to do a Post without a previous reading?


In the documentation's examples, each POST is preceded by a reading, is it possible to do a Post without this previous step?

Bye, Hervé


Solution

  • Restangular need to know to which resource you are going to post, this is a required step, otherwise it won't be able to generate the url.

    To not get data, you just need to not use get() or getList() methods.

    So any of those should work :

    var account = Restangular.service("accounts");
    account.post({data});
    
    var account Restangular.oneUrl('googlers', 'http://www.google.com/1');
    account.post({data});
    
    // the 'one()' method will allow you to use 'account.save()' later which will decide to POST or PUT accordingly
    var account = Restangular.one("accounts");
    account.post({data});