Viewing REST service responses in a browser

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)'browse_string') do |f|
    browser = ENV.fetch('BROWSER') { 'firefox' }
    puts "Starting browser #{browser} with response..."
    unless system(browser, f.path)
      warn "Error starting browser #{browser}"

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:


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

I’ve put the code on Gist as well.


  1. Cool to see I'm not the only one using Boson 🙂 Lemme know if you start a github repo of Boson libraries.

Leave a Reply

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