What is the curl Command? Examples, Flags, HTTP Requests

curl is a command-line tool to send HTTP/HTTPS/FTP requests from the terminal. Used for API testing, debugging, scripting, and CI checks.

What is the curl command?

curl (Client URL) is a command-line tool and library for transferring data with URLs. It supports dozens of protocols (HTTP, HTTPS, FTP, SFTP, SMTP, IMAP, LDAP, SCP, etc.) and is the de facto standard for making HTTP requests from the terminal. Originally written in 1996 by Daniel Stenberg, curl is bundled with most Linux distributions, macOS, and Windows 10+.

Developers use curl for testing API endpoints, debugging HTTP issues, scripting automation, downloading files, and CI/CD checks. It's also widely used as a teaching tool — almost every API documentation page includes curl examples.

Basic curl syntax

The simplest curl command sends a GET request:

curl https://api.example.com/users/42

To see headers + body:

curl -i https://api.example.com/users/42

POST with JSON body:

curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice", "email": "alice@example.com"}'

With authentication:

curl -H "Authorization: Bearer eyJ..." https://api.example.com/me

Most-used curl flags

FlagWhat it does
-X METHODSet HTTP method (GET, POST, PUT, PATCH, DELETE)
-H "Header: value"Add a request header
-d 'data' or --data 'data'Send request body (POST/PUT)
-d @file.jsonRead body from file
-F "field=value"Send multipart/form-data field
-F "file=@photo.jpg"Upload a file (multipart)
-iInclude response headers in output
-ISend HEAD request (headers only)
-LFollow redirects
-o fileSave response body to file
-OSave with remote filename
-sSilent mode (no progress bar)
-vVerbose output (debug)
-kSkip TLS cert verification (testing only)
--cookie-jar fileSave cookies to file
-u user:passHTTP Basic Auth
--max-time NTotal timeout in seconds
-w "%{http_code}"Print specific response info (status, time, etc.)

Common curl recipes

Test an API endpoint

curl -i https://api.example.com/health

POST JSON

curl -X POST https://api.example.com/orders \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"product_id": 42, "quantity": 1}'

Download a file

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

Resume an interrupted download

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

Upload a file (multipart)

curl -F "avatar=@photo.jpg" -F "username=alice" \
  https://api.example.com/upload

Follow redirects

curl -L https://example.com/short-url

Get only the HTTP status code

curl -s -o /dev/null -w "%{http_code}" https://example.com

Time the response

curl -s -o /dev/null -w "%{time_total}\n" https://example.com

Test with self-signed certificate

curl -k https://localhost:8443/health

Cookie session

curl --cookie-jar cookies.txt -d "user=alice&pass=..." https://example.com/login
curl --cookie cookies.txt https://example.com/dashboard

curl vs wget vs httpie

AspectcurlwgetHTTPie
Best forScripting, API testing, debuggingFile downloads, mirroringHuman-friendly API testing
OutputStdout (default)File (default)Stdout, color-coded
Recursive downloadNo (use wget)Yes (specialty)No
Resume downloadsYes (-C)Yes (-c)No
Protocols30+ (HTTP, FTP, SMTP, etc.)HTTP, HTTPS, FTPHTTP/HTTPS only
Pre-installedAlmost everywhereLinux only typicallyRequires install

Common curl pitfalls

  • Forgot Content-Type for JSON. -d defaults to application/x-www-form-urlencoded. Always add -H "Content-Type: application/json" for JSON.
  • Quote escaping in shell. Use single quotes around JSON to avoid bash variable expansion: -d '{"x": 1}' not -d "{\"x\": 1}".
  • Logged secrets. Bearer tokens in -H "Authorization: ..." end up in shell history. Use --header @file or env variables.
  • HTTP/2 issues. Old curl versions don't support HTTP/2; check curl --version.
  • Trailing newlines on redirected output. Add -N for unbuffered output, useful with streaming responses.
  • Wrong status code in scripts. Use -w "%{http_code}" + parse, or --fail to set non-zero exit on 4xx/5xx.

curl in CI/CD

  • Smoke tests after deploy. curl --fail https://api.example.com/health exits non-zero on 4xx/5xx.
  • Health check endpoints. Lightweight liveness/readiness checks.
  • API integration tests. Quick endpoint validation in CI scripts.
  • Performance budget tests. Combined with -w "%{time_total}" to assert response time.

FAQ: curl command

What's the difference between -d and --data-raw?

-d processes @ as "read from file". --data-raw sends literal @ characters. Use --data-raw when sending strings starting with @.

How do I send a custom HTTP method?

-X CUSTOM works: curl -X PROPFIND ... for WebDAV, -X PURGE ... for some CDN purge APIs.

How do I see the request curl sends?

-v for verbose mode (request + response). --trace-ascii file for full debug.

Can curl do parallel requests?

curl 7.66+ supports --parallel for multiple URLs in one command. For load testing at scale, dedicated tools like LoadFocus/k6/JMeter are better.

How do I handle cookies across multiple curl calls?

Save with --cookie-jar cookies.txt, send with --cookie cookies.txt.

Can I use curl as a load testing tool?

For 1-10 concurrent requests, yes. For real load testing (100s-1000s of VUs from multiple regions), use proper tools like LoadFocus.

Beyond curl: load testing at scale with LoadFocus

If you've reached the limits of curl-in-a-loop for load testing, LoadFocus runs JMeter and k6 scripts that take HTTP requests to 12,500 VUs from 25+ regions. Sign up free at loadfocus.com/signup.

How fast is your website?

Elevate its speed and SEO seamlessly with our Free Speed Test.

Free Website Speed Test

Analyze your website's load speed and improve its performance with our free page speed checker.

×