John
John

Reputation: 634

ngResource some resource for multiple URI's

I have some URI's which are sending some stats about a resource:

/web/1/stats/views
/web/1/stats/sells
/web/1/stats/instock

How can I use ngResource with those URI's without creating functions for each of them? Ideal will be to have a resource '/web/:webID/stats/' and then append view, sells, unstuck, or maybe there is a better way?

Upvotes: 0

Views: 38

Answers (1)

milks
milks

Reputation: 314

You can define a 'category' parameter in the URI: /web/:webID/stats/:category you could then either pass in the category when you make the reqeust e.g.

statsResource.query({ category: 'views' });

or define different actions for the resource, setting the category parameter to the appropriate value:

// inside resource factory method
return $resource('/web/:webID/stats/:category', null, { queryViews: { method: 'GET', params: { category: 'views' } });

Upvotes: 1

Related Questions