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

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

  •  23-09-2019
  •  | 
  •  

Question

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 ?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top