Rails Responders: Versioning an API

Disclaimer: Not sure if this is a good idea or not, but so far I like it. Let me know what you think about this on twitter @jhsu or comment on my gist.

In order to version an API I decided to try and follow what conventions I could. I decided to do something similar to Github and what’s talked about in Versioning Your APIs by setting the version in the headers ‘Accept’ param and putting ‘v1’ in the vnd suffix (is that what is called?).

Using Responders’ functionality that ActionController::Responder makes use of, I created a custom responder to determine the version of the API during a request and using the decorator pattern (through the draper gem) to have different decorators for each version and each resource.

The Responder:

In the controllers:

Update (2 Oct., 2012)

This was presented at WNYRuby 2 Oct., 2012. Here are the slides.

blog comments powered by Disqus