12 curl command examples to test APIs, headers and SSL

These curl command examples cover the most common cases: testing an API, reading headers, checking an SSL certificate and measuring a response time. Curl is an open-source command-line tool that sends a request to a URL (HTTP, HTTPS, FTP) and displays the response. Here are 12 commands to copy and paste, with their options and a sample output.
This is the network tool, not the bicep curl or the hair curl. The examples follow a common thread: the REST API of a hosting provider, used to list servers and create a snapshot.
In short
- To display headers, use
curl -I(headers only) orcurl -i(headers and body). - To send JSON,
--jsonreplaces-X POST -H ... -d ...from curl 7.82 onwards. - An invalid certificate makes curl fail with exit code 60. Don't work around it with
-kin a script. -wbreaks down DNS, TCP connection, TLS, first byte and total time.- On Windows PowerShell 5.1, type
curl.exe, becausecurlis an alias for Invoke-WebRequest.
What is curl and what is it used for?
Curl is built on the libcurl library and handles HTTP/1.1, HTTP/2 and HTTP/3, depending on the version and how it was compiled. You will usually find it already installed on mainstream Linux distributions (otherwise, apt install curl), on macOS, on Windows 10 since version 1803 and on Windows 11.
The 12 commands below are grouped by purpose: API (1 to 5), headers (6 to 8), SSL (9 and 10) and performance (11 and 12).
The curl options to know before you start
Begin with curl --version. The --json option needs curl 7.82 or later, released in March 2022, and --fail-with-body needs 7.76 or later.
| Option | What it does |
|---|---|
-X |
Sets the HTTP method (POST, PUT, DELETE and so on) |
-H |
Adds a header |
-d / --data |
Sends a request body (-d @file reads from a file) |
--json |
Sends JSON with the right Content-Type and Accept headers |
-i / -I |
Shows headers with the body / headers only (a HEAD request) |
-v |
Verbose mode: request, response, DNS, TLS handshake |
-s |
Silent: no progress bar |
-o |
Writes the response to a file (/dev/null to discard it) |
-L |
Follows redirects |
-w |
Prints variables after the request (HTTP code, timings) |
--fail |
Exit code 22 if the server answers 4xx or 5xx |
-k |
Turns off certificate verification: avoid |
Beyond curl, it helps to know the essential Linux commands for administering a VPS and the usual hosting terms (TLS, TTFB, REST API).
Curl command examples for testing a REST API (1 to 5)
Every endpoint below, such as api.example-host.com, is fictitious. Replace them with the ones in your host's API documentation, including the documentation for the OmegaCloud panel.
1. A GET request and reading a JSON response
curl -s -H "Accept: application/json"
-s hides the progress bar and -H asks for JSON. Without -X, curl sends a GET. For readable output, pipe the result through jq, an open-source tool: ... | jq '.'.
2. Sending a POST request with curl
With --json, curl switches to POST and adds the JSON headers itself. Example: creating a snapshot.
curl --json '{"name":"snap-01"}'
On an older version, the classic form still works:
curl -X POST -H "Content-Type: application/json" -d '{"name":"snap-01"}'
For a large body, -d @payload.json reads a file. The same method tests a webhook if you plan to host n8n in France: you post a JSON payload to the webhook URL.
3. PUT, PATCH and DELETE
curl -X PUT --json '{"name":"snap-02"}'
curl -X PATCH --json '{"name":"snap-02"}'
curl -X DELETE
PUT replaces the resource, PATCH changes part of it. PUT and DELETE are idempotent: repeating the call leaves the resource in the same state, so you can safely replay them after a timeout.
4. Authenticating with a bearer token or API key
Type the token in without leaving it in your shell history, then reference the variable:
read -rs API_TOKEN && export API_TOKEN
curl -s -H "Authorization: Bearer $API_TOKEN"
Some APIs expect a key in a dedicated header (-H "X-API-Key: $API_KEY"), others use Basic authentication: -u username:password. With -u username alone, curl prompts for the password. And never commit a token to a Git repository.
5. Making a script fail cleanly on an HTTP error
By default, curl returns 0 even on a 404 or a 500. Add --fail-with-body to get exit code 22 while keeping the server's error message, or capture the HTTP code directly:
code=$(curl -s -o /tmp/resp.json -w "%{http_code}" -H "Authorization: Bearer $API_TOKEN" )
[ "$code" = "200" ] || { echo "HTTP error $code"; exit 1; }
This is the basis of a cron healthcheck or a CI/CD step. If your scripts grow, a Python VPS for your bots, APIs and scripts can take over.
Displaying and sending HTTP headers (6 to 8)
To display a response's headers, use curl -I (a HEAD request, headers only) or curl -i (headers, then body).
6. curl -I and curl -i: headers only, or headers with the body
curl -I
HTTP/2 200
content-type: text/html; charset=UTF-8
cache-control: max-age=3600
strict-transport-security: max-age=31536000
Some servers answer HEAD differently from GET. In that case, make a real GET and throw the body away: curl -s -D - -o /dev/null .
7. Following redirects with -L
curl -IL
Every hop is shown: for instance a 301 to https://, then a 200. After a site migration, this is how you check HTTP to HTTPS and www to non-www.
8. Verbose mode -v for debugging
curl -v -H "User-Agent: test-curl" -H "Host: example.com"
Lines starting with * describe DNS resolution and the TLS handshake (on HTTPS requests), > the request sent and < the response received. Forcing the Host header lets you test a specific virtual host without touching DNS.
Checking an SSL certificate with curl (9 and 10)
curl -vI 2>&1 | grep -E "subject|issuer|expire" shows the issuer and the expiry date. If the certificate is invalid, curl stops with error 60.
9. Reading the issuer, the domain and the expiry date
curl -vI 2>&1 | grep -E "subject:|start date|expire date|issuer:"
subject: CN=example.com
start date: Jan 5 08:12:44 2026 GMT
expire date: Apr 5 08:12:43 2026 GMT
issuer: C=US; O=Let's Encrypt; CN=R11
These values are an example. The exact wording can vary with the TLS engine curl was built against (OpenSSL, Schannel, Secure Transport). For a plain verdict, curl -s -o /dev/null -w "%{ssl_verify_result}\n" returns 0 if verification succeeds. When the date gets close, you can install a Let's Encrypt certificate on your VPS or renew the one you have.
10. Testing a certificate before switching DNS with --resolve
curl --resolve example.com:443:VPS_IP_ADDRESS -vI
Curl contacts the new server's IP address but presents the right name (SNI), as if DNS had already switched. You can validate the certificate and the site before cutting over.
Warning:
-k/--insecure. This option turns off certificate verification, and with it any proof that you are talking to the real server. It is fine for five minutes of diagnosis, never in a production script: fix the certificate or the chain instead.
Measuring a website's response time with curl (11 and 12)
The -w option prints a breakdown of timings: DNS, TCP connection, TLS, first byte and total.
11. Breaking latency down with -w
curl -o /dev/null -s -w "DNS: %{time_namelookup}\nTCP: %{time_connect}\nTLS: %{time_appconnect}\nTTFB: %{time_starttransfer}\nTotal: %{time_total}\n"
DNS: 0.012
TCP: 0.024
TLS: 0.051
TTFB: 0.180
Total: 0.195
These values are made up. The timings are cumulative from the start of the request: here the TLS step took 0.051 − 0.024 s. A slow DNS figure points to the resolver, a large gap between TCP and TLS to the network or the TLS configuration, and a big gap before TTFB to the backend. To reuse the format, put the string in format.txt (with real line breaks) and call -w @format.txt.
12. A measurement loop and timeouts
for i in $(seq 1 10); do curl -o /dev/null -s -w "%{time_total}\n" ; done | awk '{s+=$1} END {print s/NR}'
For a healthcheck, cap the duration:
curl --fail --silent --show-error --connect-timeout 3 --max-time 10 -o /dev/null || echo "KO"
--connect-timeout limits how long connection setup can take, --max-time the total duration. Measure from a point close to your users: for a UK or European audience, a server in Paris is a sensible vantage point. OmegaCloud quotes an average latency of 12 ms on its network.
Common curl errors and Windows pitfalls
| Code | Cause | What to try |
|---|---|---|
| 6 | DNS resolution failed | Check the spelling, the DNS, /etc/resolv.conf |
| 7 | Connection refused | Check the port, the service and the firewall |
| 22 | 4xx/5xx response with --fail |
Read the HTTP code, check the URL and authentication |
| 28 | Timeout | Raise --max-time or look for slowness on the network or server side |
| 35 | TLS handshake failure | Check TLS versions, SNI and the server configuration |
| 60 | Certificate not verified | Fix the chain, date or name on the certificate, don't use -k |
On Windows PowerShell 5.1, curl is an alias for Invoke-WebRequest: type curl.exe. Recent PowerShell 7 releases no longer define that alias, but curl.exe is unambiguous on every version, so it is a good habit. In cmd, single quotes delimit nothing: escape the JSON ("{\"name\":\"snap-01\"}") or, more simply, use -d @payload.json. That last method also sorts out quoting problems in PowerShell.
Testing your APIs from a server in France
To automate these tests (cron, monitoring, API calls, webhooks), an always-on server beats a workstation. A high-performance Linux VPS gives you SSH root access, a dedicated IP address and included Anti-DDoS protection, with Ubuntu, Debian or AlmaLinux.
The OmegaCloud panel exposes a REST API and a Terraform provider, so the commands above apply to it. Check the documentation for the real endpoints. Offers are currently available for pre-order, with availability announced for 1 November 2026.
Frequently asked questions
How do I send a JSON POST request with curl?
With curl 7.82 or later, curl --json '{"name":"snap-01"}' URL is enough: the option switches to POST and adds the JSON headers. On an older version, use -X POST -H "Content-Type: application/json" -d '{...}'.
What is the difference between curl -i, curl -I and curl -v?
-i prints the response headers followed by the body. -I sends a HEAD request and prints only the headers. -v shows the whole conversation: DNS, TLS handshake, request (>) and response (<).
How do I check an SSL certificate's expiry date with curl?
Run curl -vI 2>&1 | grep "expire date". The line shows the end of the validity period. If the certificate has already expired or is invalid, curl stops with exit code 60.
How do I measure a website's response time with curl?
Use -w with %{time_namelookup}, %{time_connect}, %{time_appconnect}, %{time_starttransfer} and %{time_total}, together with -o /dev/null -s. These timings are cumulative. For an average, repeat the measurement ten times.
How do I pass a bearer token in a curl request?
Add -H "Authorization: Bearer $API_TOKEN", keeping the token in an environment variable. Avoid typing it in plain text in the command, or it will end up in your shell history.
Why doesn't curl behave as expected in PowerShell?
In Windows PowerShell 5.1, curl is an alias for Invoke-WebRequest, whose options differ. Type curl.exe to call the real program, and prefer -d @file.json to avoid quoting problems.
Where to start
Write a small healthcheck script first (example 12) and run it every minute from cron on a server based in France. A high-performance Linux VPS starts at €6.99 excl. VAT per month with no minimum term, with 1 Tbit/s Anti-DDoS protection included. The offer is available for pre-order, with availability announced for 1 November 2026.