Hi,
I'm creating a hypermedia API which is generally working really well for us, but there's one use case that I'm struggling with.
This section of the API is providing functionality to browse a catalogue of things, in this case there is a hierarchy of categories which a client can navigate providing filters on the set things in the category (basically the common features you'd expect browsing any large catalogue). To do this we provide a "Category" resource with a HAL hypermedia link to the "items" related to that category. This works really well as there are quite a lot of editorially controlled options for presenting the set of items related to a category and now all this is hidden behind the link - great.
We also have a requirement for the client to be able to present additional filter and sort options within the set of items related to the category. This is handled by templating the items link to allow the client to supply the appropriate filter / sort query parameters e.g.
_links : {
"items" : { "href" : "/items?somehiddenFilter=somevalue{&filter,sort}"}
}
Again this works well, allowing the client to control the subset of filtering it needs to know about and hiding the rest.
However the problem is that different Categories should have different default sort order (e.g. some list items alphabetically and some by date). Initially this looked easy, simply add the appropriate sort parameter in the link and it all works.
_links : {
"items" : { "href" : "/items?somehiddenFilter=somevalue&sort=date{&filter,sort}"}
}
However now when the client tries to override the sort we end up with two sort parameters and the server can't know which to respect.
Expanded link to sort by alpha:
/items?somehiddenFilter=somevalue&sort=date&sort=alpha
So the question is how to allow a link to supply a default parameter value and also allow a client to override it. Currently we have two options:
1) We could document the API to say that the sort parameter should first be stripped from the URL and then the template applied, but this feels a bit hacky.
2) We could add a "defaultSort" or other named parameter for the default value, but again this "feels" wrong
Any other options I'm missing, or reasons for or against the options above?
Thanks,
Tony