API Testing with cURL: From Basics to Advanced Techniques
Master cURL for API testing with practical examples covering authentication, file uploads, debugging, and scripting.
cURL is the Swiss Army knife of API testing. Available on virtually every operating system, it lets you test APIs without any additional tools.
Essential cURL Commands
GET Request
Simple GET
curl https://api.example.com/users
With formatted output
curl -s https://api.example.com/users | jq '.'
Include response headers
curl -i https://api.example.com/users
POST Request with JSON
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "[email protected]"}'
Authentication
Bearer token
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9..." \
https://api.example.com/protected
Basic auth
curl -u username:password https://api.example.com/admin
Advanced Techniques
Timing Information
curl -w "\nDNS: %{time_namelookup}s\nConnect: %{time_connect}s\nTTFB: %{time_starttransfer}s\nTotal: %{time_total}s\n" \
-o /dev/null -s https://api.example.com/users
File Uploads
curl -X POST https://api.example.com/upload \
-F "[email protected]" \
-F "description=My document"
cURL vs Other Tools
|---------|------|---------|--------|
Use our online tools alongside cURL to format JSON responses and decode JWT tokens.