Debug RESTful calls for fun and profit

When using ActiveResource it can be quite useful to print Webservice calls going out and XML responses coming in. It allows me to debug things, it allows me to create useful Httpmocks for testing code that uses the resource.

Somewhat unobtrusive way of doing this is, stick following code to some library file:

module ActiveResource
  class Connection
    alias_method :old_request, :request
    def request(method, path, * arguments)
      response = old_request(method, path, * arguments)
      if (response && response.code.to_i == 200 && APP_CONFIG['debug_resource_call'])
        puts("********** method is #{method} and path is #{path} ********** ")
        puts response.body

And off I can go with Httpmock

Leave a Reply

Your email address will not be published. Required fields are marked *