I’ve been hacking instead of writing during my spare time the last couple months. The result is a streamlined console application for exploring web services and web sites. It’s something of a cross between curl and the Lynx browser.
You’ll need Ruby and RubyGems. It’s known to work well under OS X against Ruby v1.8.7 and v1.9.2.
The things you can do with htty are:
Here are a few annotated htty session transcripts to get you started.
This simple example shows how to explore read-only web services with htty.
You can point htty at a complete or partial web URL. If you don’t supply a URL, http://0.0.0.0/ (port 80) will be used. You can vary the protocol scheme, userinfo, host, port, path, query string, and fragment as you wish.
The htty shell prompt shows the address of the current request.
get command is one of seven HTTP request methods supported. A concise summary of the response is shown when you issue a request.
You can follow redirects using the
You can tweak segments of the address at will. Here we are navigating the site’s path hierarchy, which you can do with relative as well as absolute pathspecs.
Here we add query-string parameters. Notice that characters that require URL encoding are automatically URL-encoded (unless they are part of a URL-encoded expression).
body-response commands reveal the details of a response.
There was some cruft in the web service’s response (a horizontal line, a passage reference, verse numbers, a copyright stamp, and line breaks). We eliminate it by using API options provided by the web service we’re talking to.
We do a Julia Child maneuver and use the
address command to change the entire URL, rather than add individual query-string parameters one by one.
Exit your session at any time by typing
The next example demonstrates htty's cookies features, as well as how to review and revisit past requests.
Notice that when cookies are offered in a response, a bold asterisk (it looks like a cookie) appears in the response summary. The same cookie symbol appears next to the Set-Cookie header when you display response headers.
cookies-use command copies cookies out of the response into the next request. The cookie symbol appears next to the Cookie header when you display request headers.
An abbreviated history is available through the
history command. Information about requests in the history includes request method, URL, number of headers (and a cookie symbol, if cookies were sent), and the size of the body. Information about responses in the history includes response code, number of headers (and a cookie symbol, if cookies were received), and the size of the body.
Note that history contains only numbered HTTP request and response pairs, not a record of all the commands you enter.
reuse command makes a copy of the headers and body of an earlier request for you to build on.
Assume that we have the following Sinatra application listening on Sinatra’s default port, 4567.
This application expects GET and POST requests and responds in various contrived ways.
Here you can see a request body being specified. Type
body-set to enter body data, and terminate it by typing Return three times consecutively.
Also note how different response codes are rendered:
As with the abbreviated history demonstrated earlier, verbose history shows a numbered list of requests and the responses they elicited. All information exchanged between client and server is shown.
You can learn how to use htty commands from within htty.
help command takes an optional argument of the abbreviated or full name of a command.
Here are some features that are coming down the pike.
The HTTPS code is broken right now. Pardon the dust.
These features will make htty better at screen-scraping.
Using any of the forthcoming
form commands will clear any non-form content in the body of the request. Adding at least one URL-encoded form parameter to the request will set the Content-Type header to application/x-www-form-urlencoded. Removing all URL-encoded form parameters will remove this header.
form— display all form parameters offered in the response
form-fill— prompt in turn for a value for each of the form inputs in the response
form-remove-all— remove all URL-encoded form parameters from the request
You will also be able to pop open a browser window containing request and response bodies.
We’ll have command history using the arrow keys, command autocompletion, and Tab key navigation of forms.
You should be able to make your own command aliases.
http-console has a nice command-line. We should have an http-console skin for htty.
Your patches are welcome, and you will receive attribution for good stuff.
Stay in touch with the htty project by following the Twitter account: get_htty.
You can also get help in the #htty channel on Freenode.