top | item 4762886

Uses for cURL

339 points| KrisJordan | 13 years ago |httpkit.com | reply

71 comments

order
[+] bentruyman|13 years ago|reply
I would strongly suggest HTTPie for the majority of these tasks: https://github.com/jkbr/httpie
[+] the_mitsuhiko|13 years ago|reply
And I will continue to pitch our curlish instead which does not replace curl but amends it: http://packages.python.org/curlish/

It just wraps curl and adds some nicer options, cookie handling, oauth and colorizing to it. Same command line you are already used to but with some extras that simplify live and make it more enjoyable.

[+] DanBC|13 years ago|reply
May I ask why? What benefits does HTTPie have?
[+] DEinspanjer|13 years ago|reply
Thanks for this recommendation. I still value tips on using cURL because it is practically ubiquitous which is helpful when you are logged into some random server, but HTTPie definitely has a very common sense usage and I think it will be very useful as a testing tool for my local machine.
[+] skrebbel|13 years ago|reply
Strongly agree. For Windows users like me, i recommend installing Python and Pip using Chocolatey Nuget and then doing a `pip install httpie` to avoid Windows Python dependency hell and still get httpie.
[+] k33l0r|13 years ago|reply
> If you only care about headers use the -I flag and the response body will be hidden

That is actually wrong. The -I flag set the request method to HEAD. So in some cases it will return different headers than a normal get request (and some servers don't implement HEAD responses at all).

[+] eik3_de|13 years ago|reply
That's why I have this in the shell config and use it daily:

  alias h='curl -sIX GET -w "Total time: %{time_total} s\n"'
It issues a GET request, only prints the response headers and displays the time it took.
[+] markild|13 years ago|reply
Very true, but let's not forget that [0]

> The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.

and that

> The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request.

[0]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

[+] KrisJordan|13 years ago|reply
Ah, great catch. Added a note about having to specify the method explicitly / that -I uses HEAD implicitly. Thanks!
[+] yread|13 years ago|reply
If you're on windows and don't feel like using the commandline you can click around in Fiddler to achieve similar things. The help is much shorter http://www.fiddler2.com/fiddler/help/composer.asp

I wasn't able to change the Host header successfully, though. A workaround is needed: https://groups.google.com/forum/?fromgroups=#!topic/httpfidd...

[+] maratd|13 years ago|reply
> If you're on windows and don't feel like using the commandline

Just install gow ( https://github.com/bmatzelle/gow ) and you'll be able to run all of those examples as intended. The command line becomes very pleasant on Windows after that one little install. It's very lightweight and well designed.

[+] swang|13 years ago|reply
The site does not work on the iPhone at all if you want to zoom in to read the text. If you start to touch and scroll the menu that was hidden away on the left decides to rear its ugly head and makes the site completely unreadable.

I'm pretty frustrated with sites that don't just have a basic two column layout. Is this a template theme? Otherwise why would you waste so much time on a left column that reflows and messes up the browser experience? Or better yet why not test this on an actual mobile browser?

I am not trying to harp on this site or the author specifically because there are certainly other offenders. This site though is quite annoying because once you finally think yougot that stupid menu out of the way, BOOM it pops right back an ruins the site again.

This is both a rant and a notice to the author since most people probably got too fed up to tell him about this problem.

[+] KrisJordan|13 years ago|reply
Thanks for the heads up. Made a quick fix by taking out affix on the column. Tried to get this up pretty quickly with Bootstrap, need to spend some more time on it this weekend. Sorry for the annoyance.
[+] cypherpunks01|13 years ago|reply
This title is a bit misleading. I was assuming that I'd be reading about how to use something that wasn't curl?
[+] KrisJordan|13 years ago|reply
It got changed, sorry. Original title was "9 uses for cURL everyone should know". Perhaps a bit assumptive.
[+] bryanlarsen|13 years ago|reply
I knew 8 of the 9, but the one I didn't (testing virtual hosts) was worth the cost of reading the entire article. Thanks.
[+] laumars|13 years ago|reply
That will only work with named vhosts. Outside of shared hosting / personal web servers, almost everyone uses IP-defined vhosts.
[+] ams6110|13 years ago|reply
I just tweak my /etc/hosts to do this.
[+] eik3_de|13 years ago|reply
> Test Virtual Hosts, Avoid DNS

> With cURL just point the request at your host’s IP address

It's not even necessary to manually look up the IP, since options have precedence:

  curl server1.example.com -H Host:\ www.example.net
looks up server1.example.com and connects to that IP with the given Host: Header. Just try the "-v" option to see what's going on.
[+] no_more_death|13 years ago|reply
I generally use wget myself. For basic HTTP debugging needs, I run ":%!wget -Sd http://www.example.com inside a new vim buffer. Then I can read the Varnish headers or whatever and figure out what's going on.

I ran into an issue where the SSL implementation was a bit dated, though, and didn't recognize how a GoDaddy cert implemented multiple hostnames -- but it turned out to follow the standard. wget was just lacking in its implementation and reporting an error when the cert was fine.

[+] RoryH|13 years ago|reply
Curl is great to have, but remembering all the options flags is a pain. Nowadays I use:

Chrome: "Postman" extension

Firefox: "REST Client" addon

...both great utilities for creating and saving any HTTP request you need.

[+] tomchristie|13 years ago|reply
I'm sure there must be other sites documenting this too, but that's a very well written and prioritized bit of documentation - nicely done.

Your echo service is pretty nifty too.

[+] DEinspanjer|13 years ago|reply
It is. One thing I just noticed though, the echo service indicates that docs are available at http://httpkit.com/echo but that URI is a 404.
[+] randomfool|13 years ago|reply
Real HTTP from the command line is 'telnet localhost 80'.
[+] planckscnst|13 years ago|reply
'nc localhost 80' FTFY
[+] sravfeyn|13 years ago|reply
I never learnt cURL, or for that matter missed many of command-line tools because of the laziness to read boring long man pages. This is a perfect example of how a man page should be. All the options explained one by one with simple examples! It took me hardly 5 minutes, now I feel confident in using cURL for my next use.
[+] goronbjorn|13 years ago|reply
This is a great resource. We use curl for sample API calls in our docs (developers.box.com/docs) because it's ubiquitous, but we've come to learn over time that knowledge of how to use curl is not ubiquitous.

Thanks for making this!

[+] alpb|13 years ago|reply
I can add -I parameter to these. It sends a HEAD request, which only returns headers, works better when you don't need the response body as in -i.