How to Test APIs with cURL: 25 Practical Command-Line Examples

Learn how to test HTTP APIs from the terminal using cURL. Ready-to-copy commands for GET, POST with JSON, headers, cookies, and bearer tokens.

cURL is the ultimate command-line tool for verifying an api example quickly without booting up heavy GUI clients. Mastering a few cURL flags accelerates testing and server debugging immensely.

Essential cURL Flags

1. Send a GET Request and Print Response Headers
curl -i https://api.open-meteo.com/v1/forecast?latitude=40.71&longitude=-74.00
2. Send a POST Request with JSON Body and Bearer Auth
curl -X POST https://api.example.com/v1/orders -H "Content-Type: application/json" -H "Authorization: Bearer my_secret_token" -d '{"itemId": 941, "quantity": 2}'