一旦我使用$ http来调用我所有的apis'端点。但最近我读到使用$ resource更加强大或最佳实践。现在我正在将所有$ http调用迁移到$ resource,并且我对如何使$ resource函数动态化了。
My api endpoint
GET: /broadcast/{gameId}
GET: /broadcast/{gameId}/players
POST: /broadcast/{gameId}/audio
POST: /broadcast/{gameId}/play/control
GET: /broadcast/{gameId}/remaining
etc..
这就是我制作工厂$资源的方式
Broadcasting: function() {
return $resource(api+"broadcast/:gameId", {},
{
getByGameId : {method: "GET", isArray: false},
getByPlayers : {method: "GET", isArray: false}, //how to add additional URI for /players
postAudio : {method: "POST", isArray: false},//how to add additional URI for /audio
postControl : {method: "POST", isArray: false}, //how to add additional URI for /play/control
getRemaining : {method: "GET", isArray: false} //how to add additional URI for /remaining
}
);
}
感谢