367 points · by _ghm2 · 7y ago · 89 comments
Migrated to Curlie [1], `alias http=curlie`, and been happy with it since. Same API, better performance and access to full `curl` flags.
> If you like the interface of HTTPie but miss the features of curl, curlie is what you are searching for. Curlie is a frontend to curl that adds the ease of use of httpie, without compromising on features and performance. All curl options are exposed with syntax sugar and output formatting inspired from httpie.
So curlie is curl. Thanks for this.
It would be interesting to create an alternative to `http-prompt` [0], using curlie and go-prompt [1] instead of HTTPie and `prompt_toolkit` [2], respectively.
[0]: https://github.com/eliangcs/http-prompt
[1]: https://github.com/c-bata/go-prompt
[2]: https://github.com/prompt-toolkit/python-prompt-toolkit
# time http google.com >/dev/null 2>&1
real 0m0.337s
user 0m0.259s
sys 0m0.036s
# time curlie google.com >/dev/null 2>&1
real 0m0.042s
user 0m0.011s
sys 0m0.005s
# time curl google.com >/dev/null 2>&1
real 0m0.039s
user 0m0.009s
sys 0m0.004sWhat’s the thinking here? If I ask for the headers, wouldn’t I want that on stdout?
I almost forked it to get both outputs into stdout haha
Asking a program for info and then getting that info on stderr seems really bizarre to me.
Is this some historical UNIXism?
defaults to GET request
http google.com
when json body exists it becomes a POST request http google.com user=65"user=65" is not valid JSON, unless you consider it a single JSON string literal.
HTTPie converts that into a JSON object.
Curl will send the data literally as you send it - if you want to send JSON, give it JSON as the body. If you want to send a "Form POST" quest, give it an encoded query string as the body.
If HTTPie detected that what you gave it was valid JSON, or whatever other media type, and used that to 'guess' the request Content-Type, that would be useful and smart.
But HTTPie not only mangles input, it mangles it in a way that is completely non obvious.
passing it "foo=bar" will send a JSON encoded object like `{"foo": "bar"}`.
passing it "foo=bar&baz=boo" will still send a JSON encoded object like `{"foo": "bar"}`.
So, it knows that ampersand is a field separator, but then promptly ignores all the content after it?
So, no. I call bullshit on "sane defaults" when it mangles data, and silently drops data it's given.
It also doesn't make it easy to use, because eventually the magic will guess wrong and it will go from magically the right thing even though I passed garbage arguments to completely the wrong thing at the drop of a hat.
An example of a "sane default" where curl falls short might be to enable redirects by default, because that is usually what the user wants (and correct client behavior).
Please explain how a well-defined key-value convention is equitable to "incomplete" or "plain wrong" arguments.
In what way is any of this opaque when it's fully documented and quite easy to follow?: https://github.com/jakubroztocil/httpie#id16
This strikes me as the best of both worlds--you're seamlessly educating the user on what is happening and what they could have done instead.
In 99% of cases httpie can assume that I'm making a POST request or a GET request with json or query params. Very rarely will I need to add custom headers, or change the Content-Type.
Yes I can explicitly define the JSON body, headers and method type every time. Or I can use a tool which uses ..... "sane defaults"
Touché sir, your argument has won the day. /s
echo '{"foo": "bar"}' | http :8000
Sounds like a curl replacement to me. From wikipedia (https://en.wikipedia.org/wiki/CURL):
"cURL is a command-line tool for getting or sending data including files using URL syntax."
This seems like a small tool with good ergonomics for http/s requests only.
I continue to be surprised by the protocols which curl supports. SMTP, IMAP, SFTP..
The thing I like about curl + jq is that I can easily switch it out for:
TEMPFILE=`mktemp`; curl -s <REQUEST> >$TEMPFILE; python -c "import json; f = open('$TEMPFILE', 'r'); d = json.load(f); <json processing logic and print statement>; f.close()"
and run in my CI environments or ship in docker images for testing purposes.
That said, I do see the potential for a tool like this. What I would like is the ability to manage different profiles for different URLs from the command line. Profiles could just be collections of header specifications - "Authorization: Bearer <blah>" or "Content-Type: application/json"
(Maybe https://github.com/postmanlabs/newman#using-newman-cli ? Didn't know about it until now.)
This is painful. In powershell this is built in and as easy as iwr url/to/json | convertfrom-json | other logic
It's a beefy package, though. Packaged in a docker image on top of alpine:3.10.3 following their installation instructions for alpine: https://gist.github.com/nkashy1/643e7a263054c02e2caceb3912f8...
The image comes in at 178 MB. alpine:3.10.3 is 5.5 MB. An alpine image in which you add bash, bash-doc, and bash-completion clocks in at 13 MB.
Sounds really powerful for personal use, but not an ideal tool for production use (e.g. when you need to spin up a pod on a Kubernetes cluster to debug an issue in production). Will definitely try it out.
xidel url -e 'logic'
and one such xidel call is enough regardless, if the url returns json, xml or html.
It doesn't seem to get much development attention though. There hasn't really been features I find useful added in the past year. The biggest issue is no support for nested JSON bodies, meaning non-trivial API calls end up just as complex as curl.
-d for body
-X for method
—-verbose to see response headers
How much “clearer” could curl get?
-M for Method
-B for Body
-RH for Request Header
you know, so you only have to know the first letter and don't have to remmeber arbitary flags?
I know that it is not that easy, but unix tools do have the problem that often the flags don't make sense on the first glance.
-d for data
-X for execute
There was a reasonable attempt at this already. There are going to opinions on either side. And through regular use the flags would become muscle memory.
Should you be sending HTTP requests to something without knowing precisely what you're doing? httpie just sorta assumes from your arguments what you're trying to do, and for me it has often been wrong. Probably works OK if you have a mostly read-only API.
Conversely something like jq is trivial to install and use almost anywhere because it is just a binary linked against libc. As a result I use it all the time.
1. pip3 install httpie.
2. python3 -m pip install httpie.
3. sudo pip install httpie.
Finally, it was working. Last week I upgraded to ubuntu 18.04 and surprise, httpie is not working. I didn't bother installing again from pip. Luckily this time, apt repository had a recent version.
Scrolling back through my terminal history, I see that I went through the same struggle with s3cmd.
So yeah, installing anything that requires python is a bit painful. Fortunately, someone in the comments mentioned https://github.com/rs/curlie which is an HTTPie alternative in golang.
Commands are a bit shorter (as it assumes json apparently) but, when working on the terminal, once I wrote my curl command I just keep repeating it anyway or just changing one parameter.
Sure, cURL can do it and if I used it frequently enough, I guess I'd remember how to use it without having to look it up every time, but for my basic and infrequent use, HTTPie is more pleasant to me and I can remember how to use it.
I don’t see any benefit of using this alias
It's not the only tool out there; sometimes cURL makes more sense depending on the context. Use the right tool for the right job!
I use it all the time for just that, the API is so simple I rarely need to check the docs.
But then I realized I'm thinking of libcurl, not curl. So maybe this isn't so bad in Python as a client tool. Does Python 3 still start up really slow though? (honest question)
$ time python3 test.py
Hello world
real 0m0.020s
user 0m0.020s
sys 0m0.000s