cURL Cookbook
On this page
Why cURL matters
cURL is the fastest way to reproduce API requests from terminals, CI pipelines, and bug reports. A good cURL snippet is a portable “truth source” for debugging.
GET request
curl -i https://example.com/api/users/42
GET with headers
curl -i -H "Accept: application/json" https://example.com/api/users/42
Bearer token
curl -i -H "Authorization: Bearer <access_token>" -H "Accept: application/json" https://example.com/api/me
POST JSON
curl -i
-X POST https://example.com/api/orders
-H "Content-Type: application/json"
-H "Accept: application/json"
-d "{ "productId": 123, "quantity": 2 }"
PATCH JSON (partial update)
curl -i
-X PATCH https://example.com/api/users/42
-H "Content-Type: application/json"
-H "Accept: application/json"
-d "{ "name": "Ada" }"
PUT JSON (replace)
curl -i
-X PUT https://example.com/api/users/42
-H "Content-Type: application/json"
-H "Accept: application/json"
-d "{ "id": 42, "name": "Ada" }"
DELETE
curl -i -X DELETE https://example.com/api/users/42
Send query parameters
curl -i "https://example.com/api/orders?status=paid&limit=20"
Upload a file (multipart)
curl -i -X POST https://example.com/api/uploads -H "Accept: application/json" -F "file=@./image.png"
Download a file
curl -L -o output.zip https://example.com/api/exports/latest
Debugging tips
- Use -i to include headers in output.
- Use -v for verbose network details.
- Use --compressed to support gzip/brotli responses.
- Use --fail-with-body (newer curl) to fail non-2xx while keeping the response body.
Checklist
- Always set Content-Type when sending JSON.
- Use Authorization header for credentials.
- Capture both request and response when reporting bugs.