Restangular POST always empty

后端 未结 1 1442
眼角桃花
眼角桃花 2021-01-18 00:55

I think I\'m not understanding how a POST is done in a RESTful api. When creating a new object in Restangular with this:

var user = {name: \"John\", id:\"123         


        
1条回答
  •  被撕碎了的回忆
    2021-01-18 01:38

    I'm the creator of Restangular. Posts should be done to collections, not to elements. So, if you want to add a user to the building, you should do something like:

    Restangular.one("building", 5).post('users', user).then(function(postedUser) {
        console.log("Success");
    })
    

    Check the post method here: https://github.com/mgonto/restangular#element-methods

    The signature is path to subelement collection, element to POST.

    Bests!

    0 讨论(0)
提交回复
热议问题