api routes with versions

Hi,

I've been trying to implement a versioned API, I went through
different versions that I didn't like.

I am wondering if I can do something like this with routes, and if
it's possible how can it be implemented:

api.example.com/items/show.xml works, no version
api.example.com/v1/items/show.xml works, v1
api.example.com/v2/items/show.xml works, v2

Basically I am wondering if Rails Routing (or rack) can detect "v1" or
"v2" and set a params[:version] variable, and then proceed as that
string is not there (regular routing).

Why don't you try

api.example.com/items/show.xml
apiv1.example.com/items/show.xml
apiv2.example.com/items/show.xml

This way you won't need to mess up with the :version param in the
code--just install separate versions and route them through the web
server.

Hope this helps.