Rails Web API Versioning

1 minute read

[2013-12-18 Why was so I attracted to the idea of versioning web APIs? I’ve never needed this.]

One way to make different versions of a web service available from the same webserver is to allow clients to prepend a version identifier to the URI path. There’s some discussion about the best way to use this but I like to default to no version identifier in URIs.

Passenger makes it easy to run different versions of your Rails web api alongside each other.

http://brandish.local/customers.json

http://brandish.local/v1/customers.json

http://brandish.local/v2/customers.json

Update Your Webserver Config

Passenger allows you to direct traffic to different instances of your app. Here I’m serving brandish_v2 if no version identified is included in the URI.

Note Passenger was failing for me because it expected application.rb to be in controllers directory. I fixed it by creating a symlink from application_controller.rb to application.rb. I’m a bit confused as I thought that had been fixed in recent versions of Passenger. Maybe the RailsBaseURI code is not up to date.