Basic Curl usage

January 4, 2022

Curl is a http client that can be used from the command line. It has tons of options and here I will list some of some that I find most useful. For a detailed usage guide, go to https://everything.curl.dev/ (maintained by the Curl author).

curl <url> will make a GET request to the given URL and print out the response. In the following I’ll list some of the options that change curl’s output and behavior.

Output options

Show verbose output (e.g TLS handshake etc.)

curl -v <url>

Hide progress bar output

curl -s <url>

Show response headers

curl -i <url>

Options that don’t take arguments can be combined like this:

curl -si <url>

Show only response headers (by making HEAD request)

curl -I <url>

Redirect output to file (e.g /dev/null)

curl -o <path> <url>

Print out HTTP status code (combine with -o /dev/null to only get status code output)

curl -w "%{http_code}" <url>

Modify request behavior

Follow redirects

curl -L <url>

Read cookies to use for request from given path

curl -b <path> <url>

(can use non-existing path, no error and cookies will be set correctly for redirects)

curl -b <non-existing-path> -L <url>

Write cookies from response to file

curl -c <path> <url>

Timeout after x seconds

curl -m <seconds> <url>

Non-GET requests

Do request other than GET

curl -X post <url>
curl -X put <url>
...

multipart/form-data POST
with file upload

curl -F <key>=@<path_to_file> <url>

with key/value pair

curl -F <key>=<value> <url>

(can use multiple -F flags to set multiple key/val, key/file pairs)

curl -F <key1>=<value1> -F <key2>=@<path_to_file> <url>

do POST with JSON body

curl --data '{"<key>": "<value>"}' <url>