1

Once I was using $http in calling all my apis' endpoint. But lately I read that using $resource is much more robust or best practice. Now I'm migrating all my $http call to $resource and I got bump on how to make $resource function dynamic.

My api endpoint
GET: /broadcast/{gameId}
GET: /broadcast/{gameId}/players
POST: /broadcast/{gameId}/audio
POST: /broadcast/{gameId}/play/control
GET: /broadcast/{gameId}/remaining
etc..

This is how I make a factory $resource

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
            }
        );
      }

thanks

user2720708
  • 455
  • 2
  • 8
  • 19

0 Answers0