Media Type Versions in OpenRasta

What is the proper way to display media types in openrasta? Up to this point, in one of our rest apis, we have specified custom media types with a version number in them:



Currently, all of these media types are only passed into their own codec, which we have defined to remove some of the default and ns tags that the XmlSerializer puts into serialization. At the top of this codec, we have:



Now we get to the point where we have clients that need custom attributes and elements in the xml, and thus we have created a new object that handles those attributes and elements that derive from the Entity. We now have the task of moving specific clients to a new entity (EntityV2), however I'm not sure how to handle this in the OpenRasta context when it comes to getting this new entity type in handlers. Here's what we've been thinking so far:

  • Add another POST method to our handler to handle the derived type
  • Create a completely new url to handle the new object
  • Create a new media type and then route requests to the new handler in some way. This would be the biggest effort as we are trying to reuse the same handler with a little bit of decision logic to determine what to do with the new elements / attributes.

Any advice would be greatly appreciated!


source to share

1 answer

I'm an openRasta noob, but I think the best approach might be to use the same handler for both versions of requests and just inject a new codec for new versions of the object.

I believe that if you create a new codec and decorate it with [MediaType("application/")]

, it should use that codec to deserialize the request instead of the v1 codec. OR content negotiation should take care of the correct codec, so your handler will not change.

It depends on whether your clients can be expected to use the "Accept" HTTP header to indicate which version of the entity they are using. If it is not, you can create a new URL and just customize it with your existing handler and new codec.

Make sense?



All Articles