93

Query parameters: http://example.com/apples?order=random&color=blue

Matrix parameters: http://example.com/apples;order=random;color=blue

  1. When should one use query parameters versus matrix parameters?
  2. Why can matrix parameters be used in the middle of a URL but query parameters cannot? For example: http://example.com/apples;order=random;color=blue/2006/archive
  3. If matrix parameters are a superset of query parameters, why not use them all the time?

You can read more about matrix parameters here: http://www.w3.org/DesignIssues/MatrixURIs.html

Gili
  • 86,244
  • 97
  • 390
  • 689

1 Answers1

113

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

    Matt Kantor
    • 1,704
    • 1
    • 19
    • 37
    bdargan
    • 1,154
    • 1
    • 8
    • 2
    • 4
      "urls with query params won't have their response cached by intermediaries/proxies". Isn't this purely an implementation-specific thing? I don't see anything in the HTTP standard that calls for this behavior... – Gili Jan 19 '09 at 23:37
    • 1
      In summary: if what you say is true why wouldn't you migrate all query parameters to matrix parameters? – Gili Jan 19 '09 at 23:38
    • 2
      @Gili he never said the behavior is mandated by HTTP. from his article: "Intermediaries (proxies) won't cache any url with a query parameter in the url. this is because in the early days of the web, they didn't trust the Cache control information from dynamically generated pages." Specs and real-world practice sometimes (or in most cases) differ. – Hendy Irawan Apr 14 '11 at 13:36
    • 6
      This answer is 3/5th wrong. The difference with respect to relative URIs and the ability to embed parameters in the middle of a path are true. All other points are wrong, in that matrix parameters will have the exact same problem once they become more popular so they are not different from query parameters in that regard. – Gili Nov 14 '12 at 20:48
    • 3
      @Gill query parameters are useful in defining optional criteria matrix parameters are supplementary information to the path variable. See this URL query: http://localhost/services/api/movies?limit=10&actor=true&name=true matrix: http://localhost/services/api/movies/actor;name?limit=10 Makes more sense when used as matrix over query. This URL proves point 5 from bdargan. – skipy Jul 01 '13 at 12:20