9 ms·
HTTPie: A cURL-like tool for humans
- pkulak 14y agoThis is a great idea. Sometimes when something is not working the last thing I want to do is poor through the curl man page before I can even get started figuring it out.
- jameswyse 14y agoThis is fantastic! Thank you!
- snissn 14y agohttp://xkcd.com/927/ http://xkcd.com/927/
- gdg92989 14y agoyeah, couldn't agree more
- kstenerud 14y agoNot applicable. This is not a new standard; merely a new tool.
- rhomboss 14y agoReplace standard with tool. Still applicable.
- benatkin 14y agoAPI docs often show examples with cURL. If people start writing examples with httpie, that's yet another thing to learn.
- kstenerud 14y agoSo by that rationale, we should have stuck with Mosaic, and Internet Explorer, Firefox, Chrome, Safari, Opera, and Konqueror are all bad things? How about the various mail clients, office products, ftp clients, torrent clients & servers, programming languages, power drills, clothing lines, gasoline engines, kitchen knives and so on? Tools are about innovation. Standards are about locking down feature sets so that tools can interact in a common way. The whole point of the xkcd comic is that too many standards makes it difficult to make tools, and adding yet another one-standard-to-rule-them-all usually backfires.
- benatkin 14y agoIt looks great! I see no reason to slight cURL, though. Its CLI was intended for humans.
- jkbr 14y agoIt's not meant to be an insult on cURL. cURL is a great library/tool and supports way more than HTTP, but the command line interface simply isn't as convenient for common HTTP as it could be. The "for humans" slogan is borrowed from the underlying python-requests library and is meant to communicate that good UX is one of the top priorities of the project. Glad you like it!
- benatkin 14y agoI don't think it's the most obvious kind of good UX, but rather good UX for people who value expressiveness, like ruby programmers. The items that change meaning based on symbols are quick to type, but it comes at the cost of clarity. curl's paramters aren't very clear either, and since it supports more than just HTTP, it's harder to go through the man page with all that it supports. I think there's still room for one that uses option names/letters to differentiate between headers and body properties rather than symbols.
- jkbr 14y agoThanks for the feedback! I tried to come up with syntax that would make the most common tasks (i.e., sending JSON objects, submitting forms, setting headers, etc) as easy as possible and also feel "natural". The reason for the chosen style is that it quite corresponds to the actual HTTP request being sent. For example, if you want to send a PATCH request with a custom header and a form field data: PATCH /patch HTTP/1.1 X-API-Token: 123 Host: httpbin.org Content-Type: application/x-www-form-urlencoded; charset=utf-8 foo=bar You can simply copy the header (X-API-Token: 123) and the data (foo=bar) and paste it to the terminal: http --form PATCH httpbin.org/post X-API-Token:123 foo=bar It's not as obvious as '--request PATCH --header X-API-Token:123 --form foo=bar', but on the other hand, the command doesn't include almost anything that wouldn't become part of the actual request, which makes it short and easy to focus on what's important.
- kodeninja 14y agoAnother alternative, in Ruby, is HTTY - https://github.com/htty/htty https://github.com/htty/htty
- 0x5a177 14y agoOne difference to note is that HTTY puts you in a REPL-like environment instead of being a one-shot command like curl.
- jparise 14y agoI'd also recommend Curlish (http://packages.python.org/curlish/ http://packages.python.org/curlish/). It performs nice JSON highlighting and also handles OAuth 2.0 token authentication. It simply wraps curl(1), so all of the familiar arguments and recipes continue to work just fine, as well.
- akvlad 14y agoI was looking for something like this a while back and found a useful firefox plugin called Poster (https://addons.mozilla.org/en-us/firefox/addon/poster/ https://addons.mozilla.org/en-us/firefox/addon/poster/). It's useful for testing a RESTful api without creating any front-end code to handle the requests. Or anything you can do with cURL just simpler.
- freestyler 14y agoI wrote a similar one for chrome https://chrome.google.com/webstore/detail/cdjfedloinmbppobahmonnjigpmlajcd https://chrome.google.com/webstore/detail/cdjfedloinmbppobah...
- roller 14y agoA coworker recently pointed us to yet another one of these, Dev HTTP Client, which has worked really well for us. https://chrome.google.com/webstore/detail/aejoelaoggembcahagimdiliamlcdmfm https://chrome.google.com/webstore/detail/aejoelaoggembcahag...
- suresk 14y agoHope a little bit of self-promotion isn't frowned upon - I have a similar app [1] on the Mac App Store. One nice thing it does is allow you to save a request in a a file, to be re-used later. A lot of folks I've talked to have used this to share test cases in a QA organization, and I think it can be kind of handy (although, the free browser-based ones are quite good, too). I'm working on adding conversion to/from cURL and wget commands, which could be helpful when working with APIs that are documented with cURL examples. It costs $2, but I'll give anyone who asks (well, up to 50 people at least) a free copy - my contact info is in my profile. 1. http://itunes.apple.com/us/app/graphicalhttpclient/id433095876?mt=12&ls=1 http://itunes.apple.com/us/app/graphicalhttpclient/id4330958...
- mjs 14y agoThe UI for curl is awful (--request to change the method??) and wget's is only slightly better, but they do have the advantage of ubiquity, and it's often useful to email/Skype complete curl or wget command lines about the place to explain how to use an API, or demonstrate problems. (e.g. Stripe and others document their API in terms of curl commands: https://stripe.com/docs/api. https://stripe.com/docs/api.) I do wish the curl UI was better, but I can't see it being trivially replaced. (It's a similar issue with git: bad UI, but every git question and answer is described in terms of the CLI, so even if you prefer a GUI client, say, you still need to be able to formulate your problem in CLI terms for anyone on stackoverflow to understand you.)
- SoftwareMaven 14y agoIt is possible to have another tool become ubiquitous (and in this case, it really would be for the best to have another tool become ubiquitous). In order to do that, though, you have to have a better tool, so this is a great start to making that happen.
- justincormack 14y agoCurl after all mostly replaced the earlier wget.
- harbud 14y agoExcept wget -r, which is still widely used and has no equivalent functionality in curl.
- brown9-2 14y agoYou can also change the request method with -X.
- jcromartie 14y agoIf by "for humans" you mean "for programmers who mostly use JSON". I have to say I'm not sending JSON with cURL too often, compared to any other payload. And when I do send JSON it's more complex than a flat set of keys and values.
- jkbr 14y agoThere is more to it than that. It provides an expressive syntax to construct all sorts of requests. You can submit forms, upload files and set headers without having to use flags. You also get syntax highlighting, ability to pipe in request data, etc. If you are sending complex JSON, it's probably stored in a file or it's the output of another program: http PUT httpbin.org/put @/data/test.json http -b localhost:8888/couchdb/ | http PUT httpbin.org/put
- Camillo 14y agoWhy not use JSON syntax for JSON instead of introducing your own, though?
- jkbr 14y agoYou can still use regular JSON syntax, if you like: echo '{"foo": "bar"}' | http url The reason for having the simplified one is that it's less verbose and usually doesn't even require you to quote it: http url foo=bar
- javajosh 14y agoYeah, most of us would forget to single quote the JSON. It is definitely more verbose too - I agree with the command-line compatible simplification.
- zeroonetwothree 14y agoI don't really think curl is much harder, e.g. curl -X PUT -d @data/test.json httpbin.org/put It also has the advantage that it supports all the options you might ever need, for example http authentication and proxies are often useful.
- vlucas 14y agoIf you are doing cURL calls as a part of testing functionality, you may want to consider using a tool like Frisby.js ( http://frisbyjs.com/ http://frisbyjs.com/ ) to create a suite of automated tests that involve HTTP calls.
- ubasu 14y agoFor website scraping, something like casperjs/phantomjs or selenium are more suitable, since they emulate a browser and evaluate javascript, which curl cannot, and it is not clear if this tool can. What are the use cases where curl is more suitable than phantomjs or selenium?
- rafaelferreira 14y agoA similar project is htty, which presents an interactive console UI to make and inspect http requests.
- mixmastamyk 14y agoI was prepared to not be impressed, but this looks nice to use. Installed.
- slurgfest 14y ago"for humans" seems to have no better meaning than "for the OS X sensibility". In other words: this is a style change rather than a productivity gain. And the superiority of the style is not obvious - unless you just HATE the style of existing tools and need to be set apart. Most humans don't operate the command line or write scripts to begin with. Those who do, usually can handle wget "http://foo/bar http://foo/bar. It took me all of a few seconds to start using wget and all of 10 minutes to have access to fancier features. (But the truth is that a certain level of complexity really just wants a script rather than ad hoc commands). So here is a new tool, and it looks nice. But it doesn't at all relieve me from having to learn syntax and conventions - I still have to go to a doc/manpage and read that same kind of technical prose. So the only effective difference is that now I am using different punctuation, like @filename and -b. But the use of this "@" character is not really consistent with anything else. So the tool is fine and I am sure people will use it but the competitive advantage is incredibly thin and the project smacks of NIH. If curl and wget are not for humans then what are they for? People who do not have that magical design sensibility. Lame code-monkeys without vision, who are not creative and different. Soulless agents of the man. This emphasis on branding over substance irks me quite a bit.
- maratd 14y ago> Most humans don't operate the command line or write scripts to begin with. I'm not a huge fan of cURL, but most people who use cURL don't use the command line either. They use the cURL library and access that functionality through a high level language (PHP, C, C++, whatever).
- TylerE 14y agoThat's true, but it's no better there, either. Here's some sample curl client code in PHP. $c = curl_init("https://someurl/some/api"); $msg = /* some data here */ $opts = array( CURLOPT_POST=>TRUE, CURLOPT_USERPWD=>"<password string>", CURLOPT_HTTPHEADER=>array("Content-type: application/json"), CURLOPT_POSTFIELDS=>$msg, CURLOPT_SSL_VERIFYPEER=>FALSE, CURLOPT_RETURNTRANSFER=>TRUE ); curl_setopt_array($c, $opts); $d = curl_exec($c); curl_close($c); Every option in that ugly argument array corresponds directly to a commandline option.
- javajosh 14y agoThis is a nice curl and wget replacement that handles a bunch of modern use-cases without a lot of hard-to-remember command-line flags. That said, there is a broader problem of "hard-to-remember command-line flags" which I have personally solved using snippet management (I use notational velocity or command history, whichever is handiest). There is no doubt httpie's interface is a lot better, but it creates another problem (again, which is somewhat universal) of installing, learning and remembering to use a new tool. This is a non-trivial problem that is a key concern for anyone evaluating a new tool, and it's a problem that only really gets solved with ubiquity. Finally, an observation that so many of our "traditional" command line tools pay no attention to usability because, at least back in the day, the problem they solved was hard. People had a choice: either put up with an (admittedly) bad interface or write their own version in C. The individual cost of learning a bad interface outweighed the cost of rewriting the tool, and so standard tools were born. And now, decades later, new generations are stuck having to learn needlessly obtuse interfaces to standard tools. We have a situation where newcomers pay the cost of developer UI laziness in perpetuity. This is, of course, a terrible outcome and it's projects like this one that are trying to change it. So I applaud the effort and hope it catches on, become ubiquitous, and I can take the curl and wget snippets out of NV.
- chernevik 14y agoDELETED This was a warning of a hazard to navigation, when a more diligent effort to remove the hazard is called for.
- javajosh 14y ago>on at least some occasions the Python client gets non-standard results, while curl and (Guido, forgive me) PHP do fine Ok, young one, here's the thing. If you see a problem like this then file a bug. Ideally write a test case. And if you're an overachiever, dig into the code and fix it. Any bug in an http client that reposts data is incredibly serious, and needs to be fixed. The other value in doing this is that you don't spread Fear, Uncertainty, and Doubt - or FUD as it is often referred to. FUD is usually ascribed to big companies trying to discourage using a competitors product, but it can also be spread by the ignorant or misinformed inadvertantly. No offense, but I think that's the case in this case, because Python is not a niche language, it's used (and it's http libraries are used) by a lot of people, and the error mode you describe is very, very serious.
- ericmoritz 14y agoSee Resty https://github.com/micha/resty https://github.com/micha/resty
- sball 14y agoYou can't just look trought the MAN-page for cURL and just LEARN stuff? I have lost my hope for humanity.
- fromhet 14y agoEverything on HN is just "hey, learn to use this complicated complex thing - in just 30 minutes! You'll be so productive with all your creative startups!" "Learn VIM essentials in this blog post!" "Never bother reading 'man curl'!" "Learn the basics of C in three easy steps!" Sometimes HN feels like a lifestyle magazine for people who dream of being PG. EDIT: Don't get me wrong, I too dream of having the same succes as PG. Why else would I be writing here?
- skeletonjelly 14y agoWhat's your criticism exactly? What kind of content would you personally like to see more of?
- fromhet 14y agoNone, merely an uneasy feeling. If you ask me personnaly, I really enjoy articles about something technically extraordinary that OP made/wrote about, amongst other things.
- dschobel 14y agoAlso not sure what your complaint is. Working at the right level of abstraction is fundamental to being a good engineer.
- fromhet 14y agoThere is no criticism really, I agree with you. But was just feeling uneasy and vented it. I welcome downvotes to my GP comment.
- deleted 14y ago[deleted]
- bmuon 14y agoI really like how writing little tools like this in Node is so simple: node -e require('request')('http://www.asdf.com/').pipe(process.stdout)
- barrkel 14y agoMy main difficulties in using wget are in organizing output location (things like -nH, --cut-dirs, -P), choosing between -nc / -c / default (rename), error / retry policy (-T / -t), logging (-a vs -o), etc. This tool doesn't really solve any of my actual problems. YMMV. It's less a cURL replacement than a web API invocation tool.
- ww520 14y agoThis is a good tool. I wish there's an editor-integrated interactive http tool. OT: Is there an Emacs package that can do interactive invocation of http? Like having a text buffer to hold all the urls. Hitting Ctrl-E on a url to invoke it, and display the http response headers and result on separate buffers.
- masto 14y agoI like it, though I got around curl's painful syntax by wrapping it in a few shell script. For example, here's my api_post script (meant to be used like "api_post users/123 first_name=Foo last_name=Bar") (pardon my incompetent shell scripting and redaction of company internals): #!/bin/sh resource="$1" shift declare -a post while [ "$1" ]; do post=("${post[@]}" "-F" "$1") shift done if [ -z "${API_BASE:=}" ]; then API_BASE=http://localhost:3000/api/v1/ echo "No API_BASE set. Using $API_BASE." fi verbose="" [ -n "$API_VERBOSE" ] && verbose="-v" if [ -z "${API_COOKIES:=}" ]; then cookies=~/.api.cookies else cookies="$API_COOKIES" fi curl -0 -k -s -S $verbose -b "$cookies" -c "$cookies" -X POST "${post[@]}" "${API_BASE}${resource}"
- stonnyfrogs 14y agoI find the implication that people who know how to use curl are inhuman to be insulting and arrogant.