将许多 URL 参数重写为更“可读”的格式

发布于 2024-12-21 10:41:24 字数 478 浏览 1 评论 0原文

上下文:具有许多(可选)搜索参数的事件系统。虽然这在一定程度上是一个用户体验问题,但我觉得这仍然属于 SO。

一个简单的 URL 可能看起来像:

example.com/events?date=X-Y-Z&type=race&location=Lapland

以及建议的“更易读”格式:

example.com/events/location:lapland|type:race|date:X-Y-Z

您认为后者并不比前者更具可读性吗?或者“重新发明”查询语法的权衡不值得?或者也许是另一个语法建议?

注意:我偏离了典型的重写events/{location}/{type}/{date},因为这些都是可选的查询过滤器,并且有没有明显的方式将值映射到其相关参数。

Context: An events system with many (optional) search parameters. Whilst this is partly a UX question, I feel this still belongs on SO.

A plain URL might look like:

example.com/events?date=X-Y-Z&type=race&location=Lapland

And the proposed 'more readable' format:

example.com/events/location:lapland|type:race|date:X-Y-Z

Would you argue that the latter is no more readable than the former? Or that the trade-off for having 'reinvented' the query syntax isn't worth it? Or perhaps another syntax suggestion?

NB: I've strayed from the typical rewrite events/{location}/{type}/{date}, since these are all optional query filters, and there'd be no discernible way to map values to their associated parameter.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

靖瑶 2024-12-28 10:41:24

如何使用 : 和 |超过=和&有什么改进吗?某些 CMS(例如 Wordpress)发出的“可读”URL 的好处是它们包含任何变量名称,而是使用每个帖子标签,例如 example.com/ Tags/laplandexample.com/tags/race/example.com/2011/12/13/,尽管我不记得任何语法对于 AND 标签,最有意义将是一个空格,如 example.com/tags/lapland race 中所示。因为这将是 x-www-urlencoded 加上一个加号 example.com/tags/lapland+race (有些浏览器会显示一个空格,有些浏览器会显示 urlencoded 形式),你会得到一个很好的助记符 (x+ y.. x 和 y,有点)。

Just how is using : and | over = and & any improvement? The gain of "readable" URLs as emitted by certain CMSes (like Wordpress) is that they do not contain any variable names, and work with per-post tags instead, e.g. example.com/tags/lapland, example.com/tags/race/, example.com/2011/12/13/, and though I have not remembered any syntax for ANDing tags, the most meaningful would be a space, as in example.com/tags/lapland race. As that will be x-www-urlencoded with a plus as example.com/tags/lapland+race (some browsers will display a space, some the urlencoded form) you get a good mnemonic (x+y.. x and y, sort of).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文