1 unstable release

0.1.0 Oct 6, 2024

#21 in #response-body

Download history 111/week @ 2024-09-30 51/week @ 2024-10-07 9/week @ 2024-10-14

171 downloads per month

MIT and LGPL-3.0-or-later

2MB
69K SLoC

C 66K SLoC // 0.0% comments Rust 2.5K SLoC // 0.0% comments Scheme 213 SLoC // 0.1% comments

fetch

fetch is a modern HTTP(S) client for the command line.

Its features include:

  • auto formatted and colored output for supported types (e.g. json, xml, etc.)
  • render images directly in your terminal
  • easily sign requests with AWS Signature V4
  • optionally use an editor to define the request body
  • progress bar for file downloads
  • automatic response body decompression for gzip, deflate, brotli, and zstd
  • and more!

Install

Download binary

Download the binary for your os and architecture here.

Install with cargo

cargo install --force --locked fetch-cli

Usage

Basic usage

# Make a simple GET request
# fetch will default to using HTTPS if no scheme is specified
fetch example.com

# Make a PUT request with inline body
fetch -m PUT --data 'request body' example.com

# Make a PUT request with inline JSON body
# The --json flag will set the content-type header to 'application/json'
fetch -m PUT --json --data '{"key":"val"}' example.com

# Send a request body from a local file
# The content-type will automatically be inferred from the file extension
fetch -m PUT --data '@local/image.jpeg' example.com

# Use an editor to define the JSON request body
fetch -m PUT --json --edit example.com

Verbosity

# By default, fetch will write the HTTP version and status to stderr.
fetch example.com
# HTTP/1.1 200 OK
#
# [response data]

# Providing the verbose flag a single time will also output the response headers
fetch -v example.com
# HTTP/1.1 200 OK
# date: Sat, 05 Oct 2024 04:42:51 GMT
# content-type: application/json; charset=utf-8
# content-length: 456
#
# [response data]

# Providing the verbose flag twice will also output the request headers
fetch -vv example.com
# GET / HTTP/1.1
# host: example.com
# accept: */*
# accept-encoding: gzip, deflate, br, zstd
# user-agent: fetch/0.1.0
#
# HTTP/1.1 200 OK
# date: Sat, 05 Oct 2024 04:42:51 GMT
# content-type: application/json; charset=utf-8
# content-length: 456
#
# [response data]

# If you don't want any metadata written to stderr, use the silent flag
fetch -s example.com
# [response data]

Headers

# Set a custom request header for the request in the 'key:value' format
fetch -H x-custom-header:value1 example.com

# Set multiple request headers
fetch -H x-custom-header:value1 -H x-another-header:value2 example.com

Query parameters

# Append a query parameter to the request in the 'key=value' format
fetch -q key=value example.com

# Parameters will be appended to any exist query parameters on the request
fetch -q key1=value1 -q key2=value2 "example.com?existing=param"

Send a request with a form body

# Send a POST request with a form body.
# Sets the content-type to 'application/x-www-form-urlencoded'
fetch -m POST -f key1=value1 -f key2=value2 example.com

Write the response body to a file

# Write the response body to a local file
fetch example.com -o 'local/file.txt'

# Write the response body to a file, disabling the progress bar
fetch example.com -o 'local/file.txt' -s

AWS signature v4

# Sign a request with aws signature v4.
# This will set the authorization, x-amz-date, and optionally the x-amz-content-sha256 headers
export AWS_ACCESS_KEY_ID=AWSACCESSKEYID
export AWS_SECRET_ACCESS_KEY=SEcrETAccESSkEY
fetch mybucket.example.com --aws-sigv4 us-east-1/s3

Images

Images will be automatically rendered in your terminal.

High quality images will be rendered in the following terminals:

  • ghostty
  • kitty
  • wezterm
  • iterm2
  • mintty
  • konsole

Low quality block-based images will be rendered in all other terminal emulators.

Supported image types are:

  • jpeg
  • png
  • webp
  • tiff

Dependencies

~39–55MB
~1M SLoC