curl

Transfer data to/from servers. Essential for testing APIs and debugging HTTP requests.

Synopsis

curl [options] [url]

When to Use It

Use curl when you need to test an API endpoint quickly, inspect HTTP headers, replay a failing request from backend logs, download files in scripts, or verify auth, redirects, and payload formatting outside the browser.

Core Options

-X METHOD

HTTP method (GET, POST, PUT, DELETE).

-H 'Header: Value'

Add custom headers.

-d 'data'

Send data in request body.

-o file

Write output to file.

-I

Fetch response headers only.

-L

Follow redirects.

-u user:pass

Basic auth.

-sS -f

Silent, show errors, fail on HTTP errors.

Usage Examples

GET JSON

Fetch JSON API response.

curl -sS https://api.github.com

POST JSON

Send JSON payload.

curl -X POST -H 'Content-Type: application/json' -d '{"name":"John"}' https://api.example.com/users

Upload File

Send multipart form data.

curl -F 'file=@report.pdf' https://api.example.com/upload

Auth Request

Basic authentication.

curl -u user:pass https://api.example.com/secure

Download with Redirects

Follow 3xx redirects and save file.

curl -L -o app.tar.gz https://example.com/app.tar.gz

Headers Only

Inspect response headers without downloading the full body.

curl -I https://devref.cc

Verbose Debugging

See request and response details while debugging connectivity or TLS.

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

Common Mistakes

  • Forgetting -L on redirected downloads is common and often makes it look like the target file is broken when curl actually saved a redirect response.
  • Many API bugs come from missing Content-Type or Authorization headers, so inspect headers before assuming the server is wrong.
  • When sending JSON, shell quoting mistakes can silently corrupt payloads. Prefer single quotes around the outer body when possible.

Related

Built for builders.