Extension-less Formats in ActiveResource

March 26th, 2008 When trying to integrate Litmus with Fetch recently we came across an API that whilst appearing RESTful, didn't quite map onto ActiveResource conventions because their URLs 404'd if we included .xml as the extension.

So I quickly whipped up a little plugin to let us specify new formats that don't include extensions.

1
2
3
4
5
6
7
class Something < ActiveResource::Base
  
  self.site = "http://someone:password@an-app.com"
  self.prefix = "/api/"
  self.format = :xml_no_extension
  
end


Now, calls to

Something.find(:all)
will generate http://an-app.com/somethings rather than http://an-app.com/somethings.xml

Perfect!

You can grab the code from the ExtensionlessFormat GitHub repository