curl Examples

Copy-paste ready examples for common tasks.

REST API

GET JSON data
curl -H "Accept: application/json" https://api.example.com/data
POST JSON
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://api.example.com/data
PUT request
curl -X PUT -H "Content-Type: application/json" -d '{"name":"updated"}' https://api.example.com/data/1
DELETE request
curl -X DELETE https://api.example.com/data/1

Authentication

Basic Auth
curl -u username:password https://api.example.com/protected
Bearer Token
curl -H "Authorization: Bearer YOUR_TOKEN" https://api.example.com/me
API Key Header
curl -H "X-API-Key: your-api-key" https://api.example.com/data

File Operations

Download file
curl -O https://example.com/file.zip
Upload file
curl -F "file=@/path/to/file.txt" https://api.example.com/upload
Resume download
curl -C - -O https://example.com/large-file.zip

Debugging

Verbose output
curl -v https://example.com
Show headers only
curl -I https://example.com
Include response headers
curl -i https://example.com