/http

A command line utility for making HTTP requests.

Primary LanguageGoMIT LicenseMIT

http

A CLI for sending HTTP requests the easiest way possible.

Features:

  • Simplified URL parsing, e.g. :1234/path becomes http://localhost:1234/path
  • Configuration file in TOML
  • URL aliases and interpolation
  • Request history
  • Starting a server on localhost (useful for development)
  • And more

Installation

Use go get github.com/lunjon/http.

Usage

To get started use http --help.

Sending requests

Examples:

# POST http://localhost:1234/api/test 
$ http post :1234/api/test --data '{"field":"value"}'
...

# GET https://api.example/resources/abbccc-122333, using header "Donald" with value "duck"
$ http get api.example/resources/abbccc-122333 --header "donald: duck"
...

Request body

Can be specified as:

  • string: http post http://example.com/api --data '{"name":"meow"}'
  • file: http post http://example.com/api --data-file r.json
  • stdin: http post http://example.com/api --data-stdin < myfile

Configuration file

The configuration file can be managed with:

  • http config: list existing configuration file
  • http config init: creates a new if none exists at ~/.config/httpcli/config.toml
  • http config edit: edits the file using editor set in $EDITOR environment variable

The configuration file can contain the following:

timeout = "5s"  # A duration
fail = false    # Always fail with an exit code != 0 if response status >= 400

# Aliases can be used for simplified URLs
[aliases]
local = "http://localhost:8080"

Aliases are a way of storing and simplifying URLs. For instance, in the example above we can send GET http://localhost:8080/path using:

http get "{local}/path"

Server

http can start a local HTTP server that responds to any HTTP request:

http serve

This is useful for testing requests, since the server will basically echo any request it receives.

Shell completion

Can be generated by using http completion.