News for hackers. Stuff that matters.
Re:Httpie: A CLI http client by pilif on Tuesday October 20, 2015 @10:13AM (#10419234)
And yet, curl is always available, widely supported by various "Copy as curl" features in debuggers and proxies and it also makes zero assumptions about content-types of form data you might want to post, so it's always very clear what's going to be posted.

It also follows unix conventions in option placement and syntax, so there's never any cognitive hurdle to cross when the question arises where to put headers, where to put form data, where to put query string data, how to handle the case of query string data being supplied using overlapping methods and what the form data is encoded in.

It also doesn't force me to write json in yet another syntax that's command-line friendly. Instead I can just write json.

Yes. HTTPie looks nicer, but the wide availability of curl and the much more predictable syntax make it a better tool for my taste.

If I need formatted JSON output, I can always pipe the result in to jq.

Re:Httpie: A CLI http client by balac on Tuesday October 20, 2015 @10:16AM (#10419253)
You don't have to stop using curl because httpie is available. I find httpie very intuitive for my own use, but would share curl commands with other devs as it is ubiquitous.
Re:Httpie: A CLI http client by cellover on Tuesday October 20, 2015 @10:20AM (#10419286)
I did not know about jq, thanks!

Without jq, you can still pipe to python json.tool module:

$ curl http://domain.com | python -m json.tool

Re:Httpie: A CLI http client by 100k on Tuesday October 20, 2015 @01:18PM (#10420456)
I used to do this, but now I use jq. The thing about the Python version is that Python doesn't have ordered dictionaries, so the output isn't in the same order as the raw JSON. jq doesn't have that issue which is nice.
Re:Httpie: A CLI http client by batbomb on Tuesday October 20, 2015 @02:03PM (#10420723)
Python does have ordered dictionaries, but the json decoder defaults to regular dictionaries. This is easily overridable with JSONDecoder.
Re:Httpie: A CLI http client by 100k on Tuesday October 20, 2015 @02:47PM (#10420978)
Is there a one-liner you can use from the shell that preserves order?
Re:Httpie: A CLI http client by hnov on Tuesday October 20, 2015 @05:07PM (#10421820)
Starting with 3.5[0] that's the standard behavior.

One liner-wise, you could create an alias

  echo '{"foo":12, "bar": 11}' | python -c 'import json as j, collections as c, sys as s; j.dump(j.load(s.stdin, object_pairs_hook=c.OrderedDict), s.stdout, indent=4)'
[0] https://github.com/python/cpython/blob/3.5/Lib/json/tool.py#...
Re:Httpie: A CLI http client by agumonkey on Tuesday October 20, 2015 @10:40AM (#10419435)
jq is almost a full fledge programming language, like xquery, surprisingly powerful (in good and bad ways). Nice to port fragile sed-grep LoC.
Re:Httpie: A CLI http client by _Codemonkeyism on Tuesday October 20, 2015 @10:35AM (#10419395)
I often use jq to extract data from REST apis, e.g. email addresses I need in a CSV file.
Re:Httpie: A CLI http client by empath75 on Tuesday October 20, 2015 @10:47AM (#10419482)
I wouldn't use this for scripting, but if I'm troubleshooting a rest endpoint or something, it might be useful.
Re:Httpie: A CLI http client by kaonashi on Tuesday October 20, 2015 @11:05AM (#10419624)
Curl's api is turrible.
Re:Httpie: A CLI http client by XorNot on Tuesday October 20, 2015 @03:40PM (#10421294)
Not in my experience. wget is always available on default installs, whereas curl I have to specifically install.
Re:Httpie: A CLI http client by dpflan on Tuesday October 20, 2015 @11:46AM (#10419888)
curl + jq is a very nice combination. Here is the jq project page and a discussion on HN about it.

1. jq project page: https://stedolan.github.io/jq/

2. jq HN Discussion: https://news.ycombinator.com/item?id=9446980

This comment from the jq HN submission discusses httpie, jq, and httpie vs. curl: https://news.ycombinator.com/item?id=9447175

Re:Httpie: A CLI http client by snockerton on Tuesday October 20, 2015 @11:52AM (#10419928)
I concur - I've tried to like httpie, but always end up going back to curl since its syntax is permanently ingrained in my fingers.
Re:Httpie: A CLI http client by michaelcampbell on Tuesday October 20, 2015 @06:15PM (#10422204)
So is vi. I still use emacs.

Using only tools based on ubiquity is rather short sighted.

Re:Httpie: A CLI http client by zatkin on Tuesday October 20, 2015 @06:35PM (#10422321)
Can we not argue about vi(m) vs. emacs? Thank you. :-)
Re:Httpie: A CLI http client by broodbucket on Tuesday October 20, 2015 @07:37PM (#10422615)
That wasn't really the point. I think they're saying that just because a tool is ubiquitous doesn't mean that it's objectively the best tool for the job in all cases. Just as vi and Emacs coexist, curl's existence doesn't make httpie pointless.