API Engineering

How to Test APIs with cURL: 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, timeouts, and bearer tokens.

By Cometflow API Engineering Team • Updated 2026-10-06

cURL is pre-installed on macOS, Linux, and modern Windows terminals, making it the universal tool for reproducing HTTP requests, inspecting response headers, and testing webhook endpoints over SSH.

1. Essential cURL Patterns for Daily Debugging

1. Inspect Status Code & Response Headers (-i)
curl -i "https://api.open-meteo.com/v1/forecast?latitude=40.71&longitude=-74.00"
2. POST JSON Payload with Bearer Token (--json)
curl -X POST https://api.example.com/v1/orders \
  -H "Authorization: Bearer tok_live_9812" \
  -H "Content-Type: application/json" \
  -d '{"itemId": 941, "quantity": 2}'
3. Measure DNS, TLS, and TTFB Timing Breakdown (-w)
curl -s -o /dev/null -w "DNS: %{time_namelookup}s | TLS: %{time_appconnect}s | TTFB: %{time_starttransfer}s | Total: %{time_total}s\n" https://example.com

Frequently Asked Questions (FAQ)

How do I convert a browser DevTools network request into code?

Right-click any request in Chrome or Firefox DevTools Network tab, select Copy as cURL, and paste it into our cURL to Code Converter to generate clean JavaScript Fetch, Axios, or Python code.