3

What is the proper way to version media types in openrasta? Up to this point on one of our rest api's we specified custom media types with the version number in them:

application/vnd.company.Entity-v1+xml

Currently all of these media types are just being passed to a custom codec that we defined to remove some of the default tags and ns tags that XmlSerializer puts in on serialization. At the top of that codec we have:

[MediaType("application/vnd.company.Entity-v1+xml")]

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

  • Add another POST method to our handler to handle the derived type
  • Create a completely new url to handle the new entity
  • Create a new media type and then route the requests somehow to a new handler. This would be the most effort as we are trying to reuse the same handler with a small amount of decision logic to determine what needs to be done with the new elements/attributes.

Any advice would be greatly appreciated!

Sean Chambers
  • 8,572
  • 7
  • 41
  • 55

1 Answers1

0

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

I believe if you create a new codec and decorate it with [MediaType("application/vnd.company.Entity-v2+xml")] it should use that codec to deserialize the request instead of the v1 codec. The OR content negotiation should take care of using the proper codec, so your handler wouldn't change.

This 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 that's not the case, you can still create a new URL and just configure it with your existing handler and the new codec.

Make sense?

Dave Nichol
  • 181
  • 3
  • 8