Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple values for sort key #36

Open
carohadad opened this issue Jan 25, 2013 · 5 comments
Open

Multiple values for sort key #36

carohadad opened this issue Jan 25, 2013 · 5 comments

Comments

@carohadad
Copy link

Hi all!

We found an issue with the specs of sorting criteria.

Let's say I want to sort by beds 'asc' and then by nurses 'asc'. According to the current specification, I should send this query:

/facilities.json?sortAsc=beds&sortAsc=nurses

Then the 'sortAsc' query key would be duplicated, and the way that's interpreted by default varies depending on your choice of language and/or framework.
(You can take a look at a discussion on the topic at: http://stackoverflow.com/questions/1746507/authoritative-position-of-duplicate-http-get-query-keys).

In order to avoid this issue we suggest to change the specification so the query is performed in the following way in future versions of the API.

/facilities.json?sort=beds:asc,nurses:asc,numServices:desc
(sorting precedence from left to right)

This would be interpreted as a plain string regardless of languages and frameworks. We think this is better because in general it's much easier to parse a string than to modify the default URI parsing behavior of the underlying framework.

And this way we can get around the limitation on sorting parameters.

Does this sound good to you?

@mwhite
Copy link

mwhite commented Mar 15, 2013

Agree with this, but can probably be added in a later version.

@edjez
Copy link
Member

edjez commented Mar 15, 2013

Suggest to postpone from 1.1/current release as we don't have sorting defined in this version; but agree with the recommendation by chadad

@mverzilli
Copy link

For the record, in http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api there's a nice example of how to address this issue. The relevant lines are:

"Sorting: Similar to filtering, a generic parameter sort can be used to describe sorting rules. Accommodate complex sorting requirements by letting the sort parameter take in list of comma separated fields, each with a possible unary negative to imply descending sort order. Let's look at some examples:

GET /tickets?sort=-priority - Retrieves a list of tickets in descending order of priority
GET /tickets?sort=-priority,created_at - Retrieves a list of tickets in descending order of priority. Within a specific priority, older tickets are ordered first"

I like the idea of using "-" to imply descending order, it's easier to read and parse than the approach we were suggesting ("sort=priority:desc, created_at:asc").

@mwhite
Copy link

mwhite commented Jun 11, 2013

+1 for -

@edjez
Copy link
Member

edjez commented Jun 11, 2013

Lol. plus one for minus here too.

On Jun 10, 2013, at 6:29 PM, Mike White [email protected] wrote:

+1 for -


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants