Useful curl Commands

12.26.2014

curl is a very useful command line tool for “transferring data with URL syntax”. curl is especially helpful when designing web APIs. curl allows you to set request headers and view response headers. Here’s a list of curl commands taken directly from the CodeSchool Surviving APIs with Rails course.

works with query strings too!

$ curl http://api.cs-zombies-dev.com:3000/zombies?weapon=axe

use the -I option to only display response headers

$ curl -I http://api.cs-zombies-dev.com:3000/zombies/7

send custom request headers with the -H option

$ curl -IH "Accept: application/json" localhost:3000/zombies

the -X option specifies the method
use -d to send data on the request

$ curl -i -X POST -d 'episode[title]=ZombieApocalypseNow' \
   http://localhost:3000/episodes

send Basic Auth credentials with the -u option

$ curl -Iu 'carlos:secret' http://localhost:3000/episodes

send Basic Auth credentials as part of the URL

$ curl -I http://carlos:secret@localhost:3000/episodes