用于检索摘要信息的 REST api 设计 [英] REST api design to retrieve summary information

查看:35
本文介绍了用于检索摘要信息的 REST api 设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,在这个场景中,我有 REST API 来管理我们将称之为组的资源.群组在概念上类似于 Google 群组中的讨论论坛.

I have a scenario in which I have REST API which manages a Resource which we will call Group. A Group is similar in concept to a discussion forum in Google Groups.

现在我有两个 GET 访问方法,我认为它们需要单独的表示.

Now I have two GET access method which I believe needs separate representations.

第一种 GET 访问方法检索有关组的最少量信息.给定一个 group_id,它应该返回最少量的信息,比如

The 1st GET access method retrieves the minimal amount of information about a Group. Given a group_id it should return a minimal amount of information like

{ 
    group_id: "5t7yu8i9io0op",
    group_name: "Android Developers",
    is_moderated: true,
    number_of_users: 34,
    new_messages: 5,
    icon: "http://boo.com/pic.png"
}

第二种 GET 访问方法检索本质上更具统计性的摘要信息,例如:

The 2nd GET access method retrives summary information which are more statistical in nature like:

{ 
    group_id: "5t7yu8i9io0op",
    top_ranking_users: {
      [ { user: "george", posts: 789, rank: 1 }, 
        { user: "joel", posts: 560, rank: 2 }  ...]
    },
    popular_topics: {
      [ ... ]
    }
}

我想分离这些数据访问方法,我目前正在计划这样的设计:

I want to separate these data access methods and I'm currently planning on this design:

GET /group/:group_id/
GET /group/:group_id/stat

只有后者才会返回组的统计信息.你怎么看?

Only the latter will return the statistical information about the group. What do you think about this ?

推荐答案

我认为您的方法没有问题.由于统计数据基本上是单独的数据,您也可以将统计数据视为单独的资源,提供一个 URI,如

I don't see a problem with your approach. Since the statistics are basically separate data, you could treat the stats as a separate resource, too, providing a URI like

GET /stat/:group_id

此外,您可以交叉引用您的资源(意味着组链接到相应的统计资源,反之亦然):

Additionally you can cross reference your resources (meaning a group links to the corresponding stat resource and vice versa):

GET /group/5t7yu8i9io0op

{ 
    group_id: "5t7yu8i9io0op",
    group_name: "Android Developers",
    is_moderated: true,
    number_of_users: 34,
    new_messages: 5,
    icon: "http://boo.com/pic.png",
    stats: "http://mydomain.com/stat/5t7yu8i9io0op"
}

GET /stat/5t7yu8i9io0op

{ 
    group: "http://mydomain.com/group/5t7yu8i9io0op",
    top_ranking_users: {
      [ { user: "george", posts: 789, rank: 1 }, 
        { user: "joel", posts: 560, rank: 2 }  ...]
    },
    popular_topics: {
      [ ... ]
    }
}

这篇关于用于检索摘要信息的 REST api 设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆