REST api design for summary information

I have a script in which I have a REST API that manages a Resource, which we will call the Group. A group is similar in its way to a forum in Google Groups.

Now I have two GET access methods that I think need separate views.

The first GET access method retrieves the minimum amount of information about the Group. Given group_id, it should return a minimum amount of information, e.g.

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

The second GET access method returns summary information that is more statistical in nature, for example:

{ 
    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 am currently planning this project:

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

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

+3
2

. - , , URI,

GET /stat/:group_id

, ( , ):

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: {
      [ ... ]
    }
}
+5

, :

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

Source: https://habr.com/ru/post/1739109/


All Articles