views:

418

answers:

1

I'm wondering whether to use matrix or query parameters in my URLs. I found an older discussion to that topic not satisfying.

Examples

At first sight matrix params seem to have only advantages:

  • more readable
  • no encoding and decoding of "&" in XML documents is required
  • URLs with "?" are not cached in many cases; URLs with matrix params are cached
  • matrix parameters can appear everywhere in the path and are not limited to its end
  • matrix parameters can have more than one value: paramA=val1,val2

But there are also disadvantages:

  • only a few frameworks like JAX-RS support matrix parameters
  • When a browser submits a form via GET, the params become query params. So it ends up in two kinds of parameters for the same task. To not confuse users of the REST services and limit the effort for the developers of the services, it would be easier to use always query params - in this area.

Since the developer of the service can choose a framework with matrix param support, the only remaining disadvantage would be that browsers create by default query parameters.

Are there any other disadvantages? What would you do?

+1  A: 

I don't really get the point here. RFC 2396 defines how URIs can be built: {scheme}://{authority}{path}?{query}

Everything after the '?' defines your query part. How it is implemented depends on your application etc. The application/x-www-form-urlencoded type defines key/value pairs for HTTP, however your values can also be multiple sets. That totally depends on your usage.

For greater compatibility I'd stick to query parameters, but if you know what you want, you can use matrix types as well.

PartlyCloudy