MediaTypeFormatter and Versioning

Topics: Web Api
Nov 3, 2011 at 12:25 PM

Hi

I doesn't seem to be possible to register a mediatypeformatter on a mediatype like this:

application/vnd.company.hierarchy+xml; version=1.0

What's the recommended way of receiving/returning different versions of an object to/from the same service?

Regards,

 

Søren

Nov 3, 2011 at 12:57 PM

Just out of curiosity, what do you see as the difference between application/vnd.company.heirarchy.v1+xml and application/vnd.company.hierarchy+xml; version=1.0 ?

Nov 3, 2011 at 1:24 PM

Nothing really.....just thought the correct way of defining a mediatype was by a type and possible a subtype.... so I was just puzzled that when adding a subtype I got an exception....

http://en.wikipedia.org/wiki/Internet_media_type

Could also be something different from version I wanted to specify as subtype....

 

Søren

 

 

Nov 3, 2011 at 1:48 PM

In your example, the type is "application", the subtype is "vnd.company.heirarchy+xml".  The "version" is a parameter of the media type.  To be honest, I have yet to find out what is the real value of using parameters versus just changing the subtype to include the version number, which is why I asked the question.  I do know that conneg considers the parameters when matching content types so it behaves the same way as changing the subtype.

Nov 3, 2011 at 2:06 PM

I don't have much input to this... I'm pretty new to this.... but you're right, it's parameters of the mediatype, so it actually make sense, not to have a different MediaTypeFormatter taking care of the same MediaType but with different parameters...

Guess it's kind of the same as having a method taking an argument or having a different method for each possible outcome of the argument....

   Get(int version)

vs:

   GetV1()

   GetV2()

...

 

Søren