api/profile/:accountname/:profilename
I am trying to use my api in a restful way using $resource. My data model is: each account has a list of profiles, and those profiles should have GET, POST, PUT. However, I generally don't get just one profile, rather all the profiles if I GET without profilename, then the whole account is returned.
var re = $resource('/api/profile/:accountname/:profilename', { accountname : '@accoutname', profilename : '@profilename' });
var r = re.get({ accountname: 'leo', profilename: 'qwe' }, function (data ) {
//change some properties on r.
//ideally, I should be able to put r is a $scope, and have two-way binding working and $save the changes to the server.
r.$save({ accountname: 'leo', profilename: 'qwe' });
});
The problem with this code is that there is no data posted to the server. It was already frustrating enough that I have to pass the parameters again in the $save method. Shouldn't it remember its parameters, since I already specified it in the get method from which I got the object I am calling $save on. If there is a better way to do it please let me know. When I inspect data in the callback, it is what I expect from the server, but now I just need to be able to post whatever itself is to the server when call $save. The official doc is so minimal that it is not obvious to know what each method takes and returns, it needs a lot of improvement.
EDIT: I solved the no data posted to server problem, and it is in the comments. The mystery still remains that I have to supply parameters in my $save method while the official doc doesn't.
EDIT2: Mystery solved, see comments.