LightAtom

curl Command: Examples for Every HTTP Task

curl talks HTTP (and much more) from the terminal. These are the examples you'll actually use, from downloading a file to posting JSON to an API.

curl -O https://example.com/file.zip

Download a file, keeping its name.

beginner15 minNeeds: Terminal (curl is built into macOS)

When to use it

Use curl to download files, test APIs, check redirects and headers, or reproduce what an app sends. macOS 15 includes curl 8.7.

Steps

  1. Fetch a page

    Prints the body to the terminal.
    curl https://example.com
  2. Download a file

    -O keeps the remote file name; -o sets your own; -L follows redirects; -C - resumes.
    curl -L -O -C - https://example.com/big.iso
  3. Send JSON to an API

    --json sets Content-Type and Accept for you and sends a POST.
    curl --json '{"title":"Hello"}' https://api.example.com/posts
  4. Add headers and authentication

    -H adds a header; -u does Basic auth.
    curl -H "Authorization: Bearer $TOKEN" https://api.example.com/me
  5. Upload a form or file

    -F sends multipart/form-data, like an HTML upload form.
    curl -F "file=@photo.jpg" https://example.com/upload
  6. Check status codes and headers

    -I shows headers only; -w prints the status code; --fail makes curl exit non-zero on HTTP errors, useful in scripts.
    curl -s -o /dev/null -w '%{http_code}\n' https://example.com

Output explained

curl prints the response body to standard output and progress or errors to standard error. Exit codes tell scripts what happened: 0 success, 6 couldn't resolve host, 7 couldn't connect, 22 HTTP error with --fail, 28 timeout, 35/60 TLS problems.

-w variables you'll reuse: %{http_code}, %{size_download}, %{time_total}, %{url_effective} (after redirects), %{remote_ip}.

Options and variations

FlagMeaningExample
-LFollow redirectscurl -L http://example.com
-o FILE / -OSave to FILE / remote namecurl -o page.html https://example.com
-X METHODHTTP methodcurl -X DELETE https://api.example.com/items/1
-d DATASend form data (implies POST)curl -d 'q=mac' https://example.com/search
--json DATASend JSON (sets headers)curl --json @body.json URL
-H 'K: V'Add a headercurl -H 'Accept: application/json' URL
-u USER:PASSBasic authenticationcurl -u admin:secret URL
--fail-with-bodyFail on HTTP errors but keep the bodycurl --fail-with-body URL
-s / -SSilent / still show errorscurl -sS URL
--max-time NGive up after N secondscurl --max-time 10 URL

Common errors

ErrorCauseFix
curl: (6) Could not resolve hostDNS or a typo; often unquoted URLs in zshQuote the URL; check DNS.
zsh: no matches foundzsh treats ? and * as globsWrap the URL in single quotes.
curl: (60) SSL certificate problemUntrusted certificate (often a proxy)Add the right CA with --cacert; avoid -k.

Do it in the app

LightAtom's connections view shows curl's connections and bytes live, handy when a download seems stuck.

Frequently asked questions

Is curl installed on a Mac?

Yes. macOS includes curl (8.7.1 on macOS 15). Homebrew offers a newer build if you need the latest features.

How do I download a file with curl?

curl -L -O URL downloads it with its original name and follows redirects. Use -o name to choose the file name.

How do I send a POST request with curl?

For JSON: curl --json '{"a":1}' URL. For form data: curl -d 'a=1&b=2' URL. For file uploads: curl -F 'file=@path' URL.

What is the difference between curl and wget?

curl is a flexible tool for single requests and APIs, built into macOS. wget focuses on downloading, including whole sites recursively, and needs Homebrew on a Mac.

LightAtom team

The people who build LightAtom, a network monitor for macOS.