开发者

How to put stats into json

开发者 https://www.devze.com 2023-03-19 10:16 出处:网络
I have a rest web service api, and I have a lot of stats that are aggregates of child data in an object. Where should I nest these stats? I thought about making them a resource all of their own, but i

I have a rest web service api, and I have a lot of stats that are aggregates of child data in an object. Where should I nest these stats? I thought about making them a resource all of their own, but it would mean a huge number of requests, instead开发者_开发问答 of including them in a single json response.

For example:

GET /data

game:{
  level: 1,
  events:[
    {event:...}
  ]
  total_events: 23,
  avg_events: 3
}

Or should things like total_events be within the events object? I haven't found any good examples of how to this.


I'm not entirely sure I understand your intentions, but I would nevertheless put such aggregate information in the parent resource, along with the listing of child URLs.

If the child link list is too much trouble to build and the client is often only interested in the statistics, then you could introduce an extra query parameter to switch between the available respresentation formats. (e.g. "stats_only", "links", or "full".)

0

精彩评论

暂无评论...
验证码 换一张
取 消