Git Product home page Git Product 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 web servers. It’s a fun way to explore web APIs and to learn the ins and outs of HTTP.

Travis CI build status Code Climate quality report Code Climate coverage report

Gemnasium build status Inch CI build status RubyGems release

See what’s changed lately by reading the project history.

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, v1.9.2, v1.9.3, v2.0, v2.1, and v2.2.

Features

  • Intuitive, Tab-completed commands and command aliases
  • Support for familiar HTTP methods GET, POST, PUT, and DELETE, as well as PATCH, HEAD, OPTIONS and TRACE
  • Support for HTTP Secure connections and HTTP Basic Authentication
  • Automatic URL-encoding of userinfo, paths, query-string parameters, and page fragments
  • Transcripts, both verbose and summary
  • Scripting via stdin
  • 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 (terminal screenshots shown here are also available in textual form).

Querying a web service

This simple example shows how to explore a read-only web service with htty.

ESV Bible Web Service example #1

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.

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. No request is made until you type a request command such as get or post.

ESV Bible Web Service example #2

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.

ESV Bible Web Service example #3

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.

ESV Bible Web Service example #4

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 or hitting Ctrl-D.

Working with cookies

The next example demonstrates htty’s HTTP Secure support and cookies features, as well as how to review and revisit past requests.

Google example #1

The https:// scheme and port 443 imply each other, just as the http:// scheme and port 80 imply each other. If you omit the scheme or the port, it will default to the appropriate value.

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.

Google example #2

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.

Google example #3

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

Now we’ll look at htty’s HTTP Basic Authentication support and learn how to display unabbreviated transcripts of htty sessions.

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

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

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

post '/submit-novel' do
  redirect '/all-good'
end

This application expects GET and POST requests and responds in various contrived ways.

Sinatra application example #1

When you change the userinfo portion of the address, or the entire address, the appropriate HTTP Basic Authentication header is created for you automatically. Notice that characters that require URL encoding are automatically URL-encoded (unless they are part of a URL-encoded expression).

When userinfo is supplied in a request, a bold mercantile symbol ( @ ) appears next to the resulting Authorization header when you display request headers (see below).

Type body-set to enter body data, and terminate it by entering two consecutive blank lines, or by hitting Ctrl-D. The body will only be sent for POST and PUT requests. The appropriate Content-Length header is created for you automatically (see below).

Different response codes are rendered with colors that suggest their meaning:

  • 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

Sinatra application example #2

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.

htty’s built-in help

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

Contributing

Report defects and feature requests on GitHub Issues.

Your patches are welcome, and you will receive attribution here for good stuff. Fork the official htty repository and send a pull request.

Development

After cloning the repository, bin/setup to install dependencies. Then rake to run the tests. You can also bin/console to get an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, bundle exec rake install. To release a new version, update the version number in lib/htty/version.rb, and then bundle exec rake release, which will create a Git tag for the version, push Git commits and tags, and push the .gem file to RubyGems.org.

News and information

Stay in touch with the htty project by following @get_htty on Twitter.

You can also get help in the #htty channel on Freenode.

Credits

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

Thanks to contributors (in alphabetical order):

License

Released under the MIT License.

htty's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

htty's Issues

The ‘userinfo-set’ command should URL-encode arguments

The userinfo-set command does not URL-encode its single argument. This means that you cannot specify a username or password that contains an @ character or a : character without manually URL-encoding it yourself.

This command should take two parameters, not one: the first for a username, and the second (optional) for a password. Both arguments should be URL-encoded in the same way the other URL segment setter commands do.

Should we URL-decode the userinfo in order to set the Authorization request header? Probably so. This does imply that a username or password containing a : character would make the userinfo ambiguous. Does userinfo nils:secret:agent indicate username nils and password secret:agent or username nils:secret and password agent? The HTTP Basic Authentication spec may not address this question.

Helpers for HTTP Auth

Especially when presented with a 401 Unauthorized response, htty should make it easy to create HTTP Basic Auth credentials apply to subsequent requests.

Refactor HTTY::Response and friends for extensibility

From IRC:

mikekelly: njonsson, what would it take to bolt on some kind of media type parser/processor that could intepret the response body?

mikekelly: or at least make it modular enough that you could bolt on your own?

mikekelly: I'm thinking if I return some media type with links in it - it would be good if I could write some kind of parser/processor that could make it's content available so I could follow links etc.

[...]

mikekelly: being able to construct the request in a functional way would be cool (if you could play with the body contents) like say: address(body.links.home.href)

njonsson: I’m not sure on that. My instinct is to proceed with a browser metaphor. Display a list of links and choose which one to follow.

njonsson: The links could be extracted by a media-type-specific parser.

mikekelly: sure - it would be beneficial to key them by link @rel

mikekelly: in html people dont' really use link relations so much but in other media types @rel is important for understanding what a link points to

mikekelly: html doesn't do that because we use text/images instead of @rel

njonsson: If the media-type parser serves up a list of links, it could decide how to label each one. Sound right?

mikekelly: yeah exactly

Tab Completion

Tab completion would make this a lot more user friendly. Not sure if there is a way to do this outside of htty with rlwrap though.

Really useful tool.

Problems installing on Mac OS X 10.6.4

There are some minor installations on Mac OS X 10.6.4

Install log below:

sudo gem install htty ~
Password:
Successfully installed htty-1.0.0
1 gem installed
Installing ri documentation for htty-1.0.0...

unrecognized option `--output'

For help on options, try 'rdoc --help'

[1] 1140 exit 1 sudo gem install htty

Also the permissions of htty look like this:
-rwxr-x--- 1 root wheel 418 Sep 7 20:30 /usr/bin/htty*

Is that correct?

Default command aliases are not optimal

It would be better to be able to type ‘b-req’ instead of ‘body-req’ for the ‘body-request’ command, for example. We could use the hyphens as “scopes” to shorten aliases. We may also remove default aliases entirely, allowing users to define their own, since we have Tab-completion.

Allow duplicate and key-only query-string parameters

Our support for query-string parameters is limited in two ways that apparently violate the convention:

  • Every query-string parameter must have both a key and a value (wrong!)
  • Query-string keys are unique — setting a parameter replaces an existing value for the key (wrong!)

We currently have the following commands for editing these collections:

  • query-set NAME VALUE
  • query-unset NAME
  • query-unset-all

We need:

  • query-add NAME [VALUE]
  • query-remove NAME
  • query-set NAME [VALUE]
  • query-unset NAME
  • query-unset-all

The changes are:

  • Make the VALUE parameter of query-set optional
  • Add query-add NAME [VALUE]
  • Add query-remove NAME

Custom response formatting

It'd be really handy if there was either built-in support or a way to register content type handlers so XML or JSON content could be displayed indented, syntax-highlighted, etc. for ease of development.

Allow get command to have path and query arguments

It would be really nice to be able to use path and query arguments with the get command. Sometimes you have a complex set of query arguments and path set up and you just want to check something, in which case it would be nice to be able to do:

get /users/m?short

Instead of issuing the related commands to build it up and then rebuilding your prior command. Not sure if there is a way to do this that I'm missing, but if not and if this is something you're interested in, I'm happy to write a patch.

Shorter response inspection commands

After using htty for a while, these definitely feel too long to me, I'd propose:

b[ody-response]
h[eaders-reponse] or head[ers-response]

When exploring APIs, I use these like crazy and there isn't anything else among current commands that deserves these single letters.

If this is acceptable, let me know and I'll write a patch. Thanks!

Add option to disable SSL cert verification

Due to working with servers without properly signed SSL certificates, I currently have a quick hack in that sets the Net::HTTP option in requests_util.rb:77

http.verify_mode = OpenSSL::SSL::VERIFY_NONE if request.uri.kind_of?(URI::HTTPS)

Could you add this option to the CLI? If not, I might be able to get around to it in a few weeks. Thanks for all your work!

Simply quit on ^d

When I press ^d (ctrl-d) now htty print a help message about the quit command, but it could simply quit without making me type in quit or qui to exit.

It's the normal behaviour of unix commands (and even irb).

Thanks!

JSON in body-set provoke an exception

I provide JSON in the request body and it looks like the interpreter doesn't like it.

http://localhost:8080/hello/json> header-set Content-Type application/json
http://localhost:8080/hello/json> header-set Content-Length 17
http://localhost:8080/hello/json> get
 200  OK -- 4 headers -- 2-character body
http://localhost:8080/hello/json> body-set 
{a: "test", b: 2}


http://localhost:8080/hello/json> get
*** Undefined method `upcase' for :get:Symbol

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.