Working Remotely? Thinking about it?

Are you a member of a geographically dispersed team? Are you thinking of working remotely, or hiring remote developers? Wide Teams is my new blog and podcast for distributed teams. Check it out for getting started guides, tips and best practices, news, interviews, screencasts, and more all about working remotely and collaborating with wide-spread teams.

Viewing REST service responses in a browser

2009 October 20
by avdi

Have you ever had this experience? You’re debugging some RESTful service and trying to figure out why it’s returning 500s. So you dump the response body to STDOUT and HOLY HAND GRENADE THAT’S A LOT OF HTML!!! Wouldn’t it be nice if you could just look at it in a browser?

Here ya go:

require 'tempfile'

def browse_string(body)
  Tempfile.open('browse_string') do |f|
    browser = ENV.fetch('BROWSER') { 'firefox' }
    f.write(body)
    f.close
    puts "Starting browser #{browser} with response..."
    unless system(browser, f.path)
      warn "Error starting browser #{browser}"
    end
  end
end

Just drop that in your debug script, in your .irbrc, or make a Boson command out of it. Then call it with the HTML you want to view:

browse_string(response.body)

It even respects the BROWSER environment convention (well, sort of).

I’ve put the code on Gist as well.

Bookmark and Share
Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.

Related posts:

  1. Copying Amazon SimpleDB Domains
  2. First and Rest in Ruby
  3. Daemonic Emacs
  4. Full Disclosure; or, What’s in your toolbox?
  5. Announcing Firetower – A command-line interface to Campfire
  • cldwalker
    Cool to see I'm not the only one using Boson :) Lemme know if you start a github repo of Boson libraries.
blog comments powered by Disqus