POST/GET using TinyGet And Ruby

At Huddle we’ve recently been adding to our JSON RESTful API.

For testing GET/POST requests, and their responses, we did originally use Fiddler2, but it doesn’t support SSL, and it’s awkward to use. We also tried Modify Headers, a Firefox extension, but it was problematic.

The solution we settled on was to use TinyGet (part of the IIS6 Resource Kit) for GET’s and a Ruby script for POST’s.

TinyGet:

A small and rather excellent application that allows one line GET commands, including assertions for HTTP return code, and response text. Here’s an example:

tinyget -t -s:4 -a:basic -u:user -p:password
-uri:/v1/json/workspaces -srv:api.huddle.net -t -status:403 -testContainString:”Success\”:true”

Especially notice the “testContainString” and “status” parameters, that allow us to make an assertion as to what we expect in the response.

We have a number of these commands to test each type of scenario. They all exist inside the same .bat file, so when testing they can all be run with a single click. I may also include the .bat file (and any others we write) as part of the Cruise Control build as TinyGet will return an error code if any of them fail.

Ruby:

Having looked at C# to create POST requests, it required a whole class, and was overly complex for what I wanted to do. Enter Ruby and Python. Both are able to perform an HTTP POST needin only a line or two of code.

In the end I chose Ruby. There’s a Window’s installer that sets up all the necessary file associations. It’s then a simple case of writing a .rb script and executing it via command line. Here’s an example:

require ‘net/http’
res = Net::HTTP.post_form(URI.parse(’https://user:password@api.huddle.net/v1/json/workspaces’), {’Title’=>’My Title’, ‘Text’=>’Body Text’})
print res.body

Conclusion:

TinyGet and Ruby allow us easily script and execute test cases, making it faster and more automated. Both also add the possibility of including the scripts as part of continuous integration.

Ruby, Not So Good:

We unfortunately hit a stumbling block with Ruby. The Windows installer for v1-186 has a bug in net\protocol.rb whereby the request always timesout rather than returning a response, or error code etc…

There are more details on this thread, and a possible fix, which didn’t work for me:

http://www.ruby-forum.com/topic/105212

So as an alternative we’re looking at either quickly writing our own C# “tinypost” or using something like curl, either via Linux or Cygwin.

2 Comments

  1. saif
    Posted 2 November, 2008 at 4:52 pm | Permalink

    Is it possible to use tinyget to write autmomated scripts to stress test a web server. if so, any help on how to script it would be really helpful

  2. Rob
    Posted 14 November, 2008 at 1:43 am | Permalink

    I’m not so sure about stress testing, but with regards to an automated script just create a .bat file.

    Within it place each command:

    %PathToTinyGet%\tinyget.exe -s:4 -t -a:basic -u:myusername -p:mypassword -uri:/api/example/url -srv:my.server.com -status:200 -testContainString:”Success\”:true”

    So just put 20 commands in a .bat file. Then you need to find a way of getting the .bat file to run over and over, and also multiple instances. It might be worth doing this via more than one pc.

    WCAT (Web Capacity Analysis Tool) may suit your needs more. You can get it at the below link:
    http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1466

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*