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

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

Previous Articles

Hosting multiple SSL sites with IIS6


Chilli Fives


Linux Mint


Creating API documentation


Configuring CruiseControl.Net


Defining a development tree


Converting AVI’s for the Samsung YP-P2


Overclocking an Intel Core 2 Q6600


D40X shortcomings


Online collaboration


Handling CSS and JavaScript using Rewrite Rules in IIS


Incremental backups with rsync


Securely deleting files in Ubuntu


Setting up Ubuntu Hardy Heron


My Blog

A blog about .Net, Linux, Traveling, Photography and Cycling (and possibly Martial Arts if I get off my backside). I'll try to review some food too, mainly cookies and Indian food.