I have a RESTful web application that supports multiple sort fields on a collection of items. Is there a common convention for encoding these sort fields into the query string o
What about a fully PHP compliant version like this one:
http://myapp.com/books?sort[0][name]=author&sort[0][dir]=asc&sort[1][name]=datepublished&sort[1][dir]=desc&count=12
A bit longer but much convinient and as I've said, compliant with PHP. ASP.NET might have implemented support for this format also.
This will create an array, sort, directly where each element of sort has a name and dir property.
I've done this before using the standard SQL sorting syntax. There are numerous parsing functions and techniques out there.
http://myapp.com/books?sort=author asc,datepublished desc&count=12
which would be encoded to
http://myapp.com/books?sort=author+asc,datepublished+desc&count=12
For REST, I prefer a more intuitive syntax:
http://myapp.com/books?sort=+author,-datepublished&count=12
And more elaborated (without '+' sign):
http://myapp.com/books?sort=author,-datepublished&count=12
Easy to remember...