3 ms·
I find curl to be a great tool, but a poor CLI. Problem is, I'm not sure how to make a great HTTP CLI. Many have tried, but everything I've always seen leaves
by cryptonector 7y ago
I find curl to be a great tool, but a poor CLI. Problem is, I'm not sure how to make a great HTTP CLI. Many have tried, but everything I've always seen leaves me wanting.
There are several complications:
- URI building (things that need URL escaping)
- path components
- query parameters
- headers
- including common standard ones that should have
their own command-line options
- things like ETags that can benefit from storing
them in xattrs
- things like conditional requests and range
requests (think download restart)
- whether there's a body
- whether it's an "HTML form" or something else
- Content-Type
- whether to chase redirects
- trust anchors for TLS (HTTPS)
- what to do with response headers
- how to integrate filtering of response body vs
headers (can't use stderr for either)
- authentication options
- cookie jars
- proxies and proxy auth
HTTP is such a complex beast that using it from a shell feels fraught with peril.
For ease of use in a functional way, it'd be nice if, for example, one could set a header value as-is on the command-line, but also by reading from a file (or possibly a pipe, so read only once).
Perhaps something like:
$ VERB $base_URI [options]
with options for:
- appending URI local part elements
- adding query parameters
- adding headers
- specifying where to write response headers
- specifying where to write response body
- if a file, maybe set [some] response headers
as xattrs!
- specifying request body source (default: stdin
for VERBs that normally have a request body)
- trust anchors
- authentication
Examples:
$ # GET with various options:
$ GET https://base-URI-here \
-a local-part-element \
-q param value -q ... \
-H header value ...
$
$ # POST with file as request body source
$ POST https://base-URI-here \
--file file
$ # POST with HTML form specified on command-line
$ POST https://base-URI-here \
--form field value --form field value ...
$
$ # And so on for all HTTP methods
Besides the options shown above, which are fairly obvious, it'd be nice to have:
--rheaders PATH # where to put headers
--xheader header # save given response header
# value as an xattr
-T trust_anchors.pem # or a directory, or whatever
-C client_cert_and_key.pem
-U username # for Basic, DIGEST, SCRAM
--password-file FILE # for Basic, DIGEST, SCRAM
-N ... # For Negotiate. This could
# be key/value pairs that can
# be used with
# gss_acquire_cred_from()
-J ... # Get a JWT token and use it
A convention for using xattrs for storing Content-Type and ETag (and a few other things perhaps) would be very very nice.