Extension-less Formats in ActiveResource

26 March 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

Comments

  1. Mike Larkin Says:

    Thanks for publishing this!

    We’ll flesh out the API to be completely RESTful as well as supporting only GET & POST (as it does now for the sake of clients that can’t use all 4 HTML methods).

    You rock!

  2. David Says:

    Hey Mike.

    No worries! We really like the look of Fetch so we’re looking forward to starting using it and integrating it with Litmus.

Sorry, comments are closed for this article.