开发者

Does it make sense to use internal anchors for filtering a REST API's representation?

开发者 https://www.devze.com 2022-12-25 18:46 出处:网络
As a follow up to my previous question about REST URIs for retrieving statistical information for a web forum Resource, I want to know if it is possible to use the internal a开发者_运维知识库nchors as

As a follow up to my previous question about REST URIs for retrieving statistical information for a web forum Resource, I want to know if it is possible to use the internal a开发者_运维知识库nchors as filter hints. See example below:

a) Get all statistics:

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

b) GET only popular topics

GET /group/5t7yu8i9io0op/stat#popular_topics
{ 
    group_id: "5t7yu8i9io0op",
    popular_topics: {
      [ ... ]
    }
}

c) GET only top ranking users

GET /group/5t7yu8i9io0op/stat#top_ranking_users
{ 
    group_id: "5t7yu8i9io0op",
    top_ranking_users: {
      [ { user: "george", posts: 789, rank: 1 }, 
        { user: "joel", posts: 560, rank: 2 }  ...]
    }
}

Or should I be using query parameters ?


Not sure what you are trying to do exactly, but make sure you understand that fragment identifiers are not seen by the server, they are chopped off by the client connector.

See: http://www.nordsc.com/blog/?p=17


I've never seen anchors being used that way - it's interesting. That being said, I'd suggest using query parameters for a couple of reasons:

  1. They're standard - and consumers of your api will be comfortable with them. There's nothing more annoying that dealing with a quirky api.

  2. Many frameworks will auto-parse the query parameters and set them in a dictionary on the request object (or whatever analogue exists in your framework / http server library).


I think it would make more sense to have:

/group/5t7yu8i9io0op/stat/top_users
/group/5t7yu8i9io0op/stat/popular_topics
/group/5t7yu8i9io0op/stat/new_topics
/group/5t7yu8i9io0op/stat/user/george


No you cannot do that because as Jan points out the server will never see that fragment identifier. Literally, that part of the url will not reach the server.

0

精彩评论

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