views:

1705

answers:

2

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

+2  A: 

I haven't heard about Matrix parameters before, but they seem only a different convention from Query parameters.

  1. It depends on your project.
  2. It is a matter of convention. Traditionally GET parameter passing from HTML forms is done via the query parameters where '/' doesn't have any special meaning, and Matrix parameters have '/' defined as a character with special meaning.
  3. They are not a superset, just a different convention.

I don't really get these Matrix parameters, it seems to be only a random URL convention, translated by mod_rewrite and then passed to the actual engine to parse. This way you can interpret '/' as you please.

bandi
Some clarifications: '/' doesn't have a special meaning for matrix parameters. It's a path separator in either case. Matrix parameters are nothing magical, apparently they're valid URI components that's only recently started gaining popularity.
Gili
They're perfectly valid, no doubt. Being a path separator makes the '/' special -- it can't be the part of a name or value while in traditional query parameters it can.
bandi
Good point! I guess I'd need to escape them.
Gili
+11  A: 

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

    bdargan
    "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
    In summary: if what you say is true why wouldn't you migrate all query parameters to matrix parameters?
    Gili