用于多重排序的URL查询字符串约定 [英] URL query string convention for multiple sort
问题描述
我有一个RESTful Web应用程序,它支持项目集合上的多个排序字段。将这些排序字段编码到URL的查询字符串中是否有一个通用约定?我正在考虑如下模式:
http://myapp.com/books?sort=author:asc, datepublished:desc& count = 12
这样可以按作者的顺序排列图书集, 。
基本上,我需要一个方便的方法来为查询字符串中的名称/值对创建名称/值对。我也需要做一些类似于上面的过滤器参数的例子。
Rails或ASP.NET MVC是否有这样的模式?还有其他的框架已经建立了处理这个问题的方法吗?我宁愿使用一个熟悉的格式,而不是滚动我自己的。
我也更喜欢使用尽可能少的URL百分比编码的格式。
在使用标准的SQL排序语法之前,有很多解析函数和技术。
http://myapp.com/books?sort=author asc,datepublished desc& count = 12
将被编码为
http://myapp.com/books?sort=author+asc,datepublished+desc&count=12
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 of a URL? I'm considering a pattern like the following:
http://myapp.com/books?sort=author:asc,datepublished:desc&count=12
This would sort the collection of books by author and then by date published.
Basically, I need a convenient way for the name-value pairs in my query string to have name-value pairs of their own. I'll need to do something similar to the above example for filter parameters, too.
Does Rails or ASP.NET MVC have a pattern for this? Are there other frameworks that have established ways for dealing with this issue? I'd rather use a familiar format than roll my own.
I'd also prefer a format that uses as little URL percent-encoding as possible.
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
这篇关于用于多重排序的URL查询字符串约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!