http2-cli

1.1.2 • Public • Published

http2-cli · Build Status License

Modern and lightweight command line HTTP/2 client.

Install

npm

$ npm install -g http2-cli

Since version 5.2.0, a new package runner tool called npx is shipped with npm. With this new tool you can run any node package binary from the command line without installing it globally first. So you can run http2-cli with the following command line:

$ npx http2-cli --help

Yarn

$ yarn global add http2-cli

Usage

http2 <method> <url> [headers..]
 
Positionals:
  method   HTTP method  [required] [choices: "DELETE""GET""HEAD""OPTIONS""POST""PUT""PATCH"]
  url      HTTP URL to request  [required]
  headers  HTTP headers to send with the request, e.g. Content-Type:application/json
 
Options:
  --help       Show help  [boolean]
  --version    Show version number  [boolean]
  --auth       Specify the authentication credentials  [string]
  --auth-type  Specify the authentication mechanism  [choices: "Basic""Bearer"] [default: "Basic"]
  --insecure   Disable the host SSL/TLS certificate verification  [boolean]
  --verbose    Display the HTTP response headers  [boolean]

Examples

Here are some command examples with the corresponding output:

GET request with basic authentication

$ http2 get https://nghttp2.org:443/httpbin/basic-auth/test/test --auth test:test
{
  "authenticated"true,
  "user""test"
}

POST request with redirected input

$ http2 post https://nghttp2.org:443/httpbin/post Content-Type:application/json < foo.json
{
  "args": {},
  "data""{\n  \"bar\"\"baz\"\n}\n",
  "files": {},
  "form": {},
  "headers"{
    "Content-Type""application/json",
    "Host""nghttp2.org:443",
    "Transfer-Encoding""chunked"
  },
  "json"{
    "bar""baz"
  },
  "origin""129.122.96.213",
  "url""https://nghttp2.org:443/httpbin/post"
}

️️Docker

For docker ❤️ you can run http2-cli with docker. You can use a prebuilt docker image or build your own. For example the following command run the latest prebuilt docker image of http2-cli:

$ docker run --rm kevinpollet/http2-cli:latest --version
http2-cli/1.1.0 linux-x64 node-v12.3.1

With docker, it's also possible to use Unix redirections and pipes! Try the following commands:

$ docker run --rm -i kevinpollet/http2-cli:latest post https://nghttp2.org/httpbin/post < foo.json
{
  "args": {},
  "data""{\n  \"bar\"\"baz\"\n}\n",
  "files": {},
  "form": {},
  "headers"{
    "Host""nghttp2.org:443",
    "Transfer-Encoding""chunked"
  },
  "json"{
    "bar""baz"
  },
  "origin""129.122.96.213",
  "url""https://nghttp2.org:443/httpbin/post"
}
 
echo -e '{ "hello": "world" }' | docker run --rm -i kevinpollet/http2-cli:latest post https://nghttp2.org/httpbin/post | jq ".json"
{
  "hello""world"
}

Contributing

✨Contributions are welcome ✨

See CONTRIBUTING.md for more information and how to get started.

License

MIT

Package Sidebar

Install

npm i http2-cli

Weekly Downloads

1

Version

1.1.2

License

MIT

Unpacked Size

18.5 kB

Total Files

16

Last publish

Collaborators

  • kevinpollet