Code Monkey home page Code Monkey logo

htty's Introduction

                 s         s
  .uef^"        :8        :8      ..
:d88E          .88       .88     @L
`888E         :888ooo   :888ooo 9888i   .dL
 888E .z8k -*8888888 -*8888888 `Y888k:*888.
 888E~?888L  8888      8888      888E  888I
 888E  888E  8888      8888      888E  888I
 888E  888E  8888      8888      888E  888I
 888E  888E .8888Lu=  .8888Lu=   888E  888I
 888E  888E ^%888*    ^%888*    x888N><888'
m888N= 888>   'Y"       'Y"      "88"  888
 `Y"   888   __  .__                  88F
      J88" _/  |_|  |__   ____       98"
      @%   \   __\  |  \_/ __ \    ./"
    :"      |  | |   Y  \  ___/   ~`
            |__| |___|  /\___  >
            __________\/_____\/____________________
           /   |   \__    ___/\__    ___/\______   \
          /    ~    \|    |     |    |    |     ___/
          \    Y    /|    |     |    |    |    |
           \___|_  / |____|     |____|    |____|
           ______\/___________________.___.
           \__    ___/\__    ___/\__  |   |
             |    |     |    |    /   |   |
             |    |     |    |    \____   |
             |____|     |____|    / ______|
                                  \/

htty is a console application for interacting with HTTP servers. It’s something of a cross between curl and the Lynx browser.

Installation

It couldn’t be much easier.

$ gem install htty

You’ll need Ruby and RubyGems. It’s known to work well under OS X against Ruby v1.8.7 and v1.9.2.

Features

  • Intuitive commands and command aliases

  • Support for familiar HTTP methods GET, POST, PUT, and DELETE, as well as HEAD, OPTIONS and TRACE

  • Automatic URL-encoding of query-string parameters and URL fragments

  • Transcripts, both verbose and summary

  • Dead-simple cookie handling and redirect following

  • Built-in help

The things you can do with htty are:

  • Build a request – you can tweak the address, headers, cookies, and body at will

  • Send the request to the server – after the request is sent, it remains unchanged in your session history

  • Inspect the server’s response – you can look at the status, headers, cookies, and body in various ways

  • Review history – a normal and a verbose transcript of your session are available at all times (destroyed when you quit htty)

  • Reuse previous requests – you can refer to prior requests and copy them

Examples

Here are a few annotated htty session transcripts to get you started.

Querying a web service

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, 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.

The 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 follow command.

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).

The headers-response and 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 quit.

Working with cookies

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.

The 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.

The reuse command makes a copy of the headers and body of an earlier request for you to build on.

Understanding complex HTTP conversations at a glance using history

Assume that we have the following Sinatra application listening on Sinatra’s default port, 4567.

require 'sinatra'

get '/all-good' do
  [200, [['Set-Cookie', 'foo=bar; baz']], 'Hello World!']
end

get '/huh' do
  [404, 'What?']
end

get '/hurl' do
  [500, 'Barf!']
end

post '/give-it-to-me' do
  redirect '/all-good'
end

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:

  • Response codes between 200 and 299 appear black on green to indicate success

  • Response codes between 300 and 399 appear white on blue to indicate redirection

  • Response codes between 400 and 499 appear white on red to indicate failure

  • Response codes between 500 and 599 appear flashing black on yellow to indicate a server error

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.

Getting help

You can learn how to use htty commands from within htty.

The help command takes an optional argument of the abbreviated or full name of a command.

Coming soon

Here are some features that are coming down the pike.

Commands for streamlining web form submission

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-add name value – add a URL-encoded form parameter for the request, using the specified name and value

  • form-remove name – remove a URL-encoded form parameter from the request, using the specified name

  • 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.

Shiny curses goodness

We’ll have command history using the arrow keys, command autocompletion, and Tab key navigation of forms.

Custom command aliases and shell emulation of http-console

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.

Contributing

Your patches are welcome, and you will receive attribution here for good stuff.

Fork the official htty repository located at github.com/htty/htty and send a pull request to htty.

News and information

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.

Credits

The author, Nils&nbsp;Jonsson, owes a debt of inspiration to the http-console project.

Thanks to contributors:

  • Bo Frederiksen (bofrede) for work on the CLI

  • Robert Pitts (rbxbx) for work on RSpec specs

License

Released under the MIT&nbsp;License.

htty's People

Contributors

bofrede avatar njonsson avatar rbxbx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.