Tuesday, August 16, 2011

using the q MIME type property in REST

In REST, client can use the q MIME type property. This property is a numeric value between 0.0 and 1.0, with 1.0 being the most preferred.

For example:

Accept: text/*;q=0.9, */*;q=0.1, audio/mpeg, application/xml;q=0.5

the preference order is as follows:



  1. audio/mpeg

  2. text/*

  3. application/xml

  4. */*


The audio/mpeg type is chosen first because it has an implicit qualifier of 1.0. Text types come next as text/* has a qualifier of 0.9. Even though application/xml is more specific, it has a lower preference value than text/* so it follows in the third spot. If none of those types matches the formats the server can offer, anything can be passed back to the client.

No comments:

Post a Comment