什么时候使用查询参数和矩阵参数?

查询参数 : http://example.com/apples?order=random&color=blue

矩阵参数 : http://example.com/apples;order=random;color=blue

  1. 什么时候应该使用查询参数和矩阵参数?
  2. 为什么矩阵参数可以在 URL 中间使用,而查询参数不能? 例如: http://example.com/apples;order=random;color=blue/2006/archive
  3. 如果矩阵参数是查询参数的超集,为什么不一直使用它们呢?

你可以在这里了解更多关于矩阵参数的信息: http://www.w3.org/DesignIssues/MatrixURIs.html

32373 次浏览

The differences between Matrix parameters and Query Parameters are much more than just convention.

The main differences are:

  • urls with query params won't have their response cached by intermediaries/proxies (at present)
  • matrix parameters may appear anywhere in path
  • calculating the relative uri is different
  • query params are generally abused to add new verbs instead of using existing methods on resources
  • matrix parameters are not resources, they are aspects that help reference a resource in an information space that is difficult to represent within a hierarchy
  • I've written it up in more detail and with more references in Query vs. Matrix Parameters