curl
Transfer data to/from servers. Essential for testing APIs and debugging HTTP requests.
Synopsis
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 METHODHTTP method (GET, POST, PUT, DELETE).
-H 'Header: Value'Add custom headers.
-d 'data'Send data in request body.
-o fileWrite output to file.
-IFetch response headers only.
-LFollow redirects.
-u user:passBasic auth.
-sS -fSilent, show errors, fail on HTTP errors.
Usage Examples
GET JSON
Fetch JSON API response.
curl -sS https://api.github.comPOST JSON
Send JSON payload.
curl -X POST -H 'Content-Type: application/json' -d '{"name":"John"}' https://api.example.com/usersUpload File
Send multipart form data.
curl -F 'file=@report.pdf' https://api.example.com/uploadAuth Request
Basic authentication.
curl -u user:pass https://api.example.com/secureDownload with Redirects
Follow 3xx redirects and save file.
curl -L -o app.tar.gz https://example.com/app.tar.gzHeaders Only
Inspect response headers without downloading the full body.
curl -I https://devref.ccVerbose Debugging
See request and response details while debugging connectivity or TLS.
curl -v https://api.example.com/healthCommon 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.