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

StackOverflow https://stackoverflow.com/questions/2551262

  •  23-09-2019
  •  | 
  •  

문제

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 anchors 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top