A Logging RestClient

restclient

Tue Aug 19 12:04:00 -0700 2008

I keep thinking I’ll run out of things to add to RestClient, but then I keep wanting more features. So here comes 0.7, with gzip/deflate support and client-side logs.

Gzip/deflate decoding on output bodies is automatic: RestClient asks for it via the accent-content header, so you’ll get faster download times on servers that support it.

Client-side logs are something I’ve wanted for a while, since service architecture sends REST call flying all over the place. Servers log requests (e.g., log/production.log), so why not clients?

After you’ve run gem install rest-client, try this:

$ RESTCLIENT_LOG=stdout restclient http://rest-test.heroku.com
>> post '/resource', :person => { :name => 'Adam' }
RestClient.post "http://rest-test.heroku.com/resource", "person[name]=Adam", :content_type=>"application/x-www-form-urlencoded"
# => 200 OK | text/html 141 bytes

The bottom two lines are the log. You don’t need to use the restclient shell; this works with any program that uses RestClient. Specify stdout, stderr or the full pathname to a logfile. You can also set the log within the program via RestClient.log = '/tmp/myrestcalls.log'.

Even better: the log output format is valid Ruby. So you can replay one or more rest calls by pasting any portion of the log into a restclient shell or a standalone Ruby script.

RDocs.