URL query string convention for multiple sort

后端 未结 3 477
醉酒成梦
醉酒成梦 2021-02-01 06:59

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

相关标签:
3条回答
  • 2021-02-01 07:25

    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.

    0 讨论(0)
  • 2021-02-01 07:41

    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
    
    0 讨论(0)
  • 2021-02-01 07:43

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

    0 讨论(0)
提交回复
热议问题