--- title: curl โ€” HTTP requests and diagnostics date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: A tool that sends HTTP requests and checks responses. Essential for service checks and API testing. tags: program, Network and Firewall, curl --- **๐Ÿ’ฌ "curl command"** curl **sends HTTP requests and checks responses**. It is the standard tool for web/API inspection. Combinations like -I for headers only, -s/-o for quiet output, and -m for timeout are often used. - **Concept**: Sends requests over various protocols and prints the response. - **Status code**: Use -o /dev/null -w '%{http_code}' to extract only the code. - **Headers**: Use -I to view response headers. - **Body**: Prints the response body by default. ## Commonly used options | Option | Description | | --- | --- | | -I | Requests headers only (HEAD) | | -s | Suppresses progress/error output | | -m | Sets the overall operation timeout | | -w '%{http_code} %{time_total}' | Prints status code and elapsed time | | -o /dev/null | Discards the body | ## 3 essential command combinations - `curl -sI https://example.com | head -1` โ€” Check response status and server headers - `curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1/health` โ€” Check health check status code - `curl -s -m 5 -X POST -H 'Content-Type: application/json' -d '{"ping":true}' http://127.0.0.1/api/ping` โ€” Check API behavior **๐Ÿ’ฌ "Show me an example that follows operational policy"** I've organized situations you commonly encounter on production servers in order. ### Step 1 ยท Check status code First check whether the service responds. ``` curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1/health ``` ### Step 2 ยท Check headers Look at redirect, cache, and server information. ``` curl -sI http://127.0.0.1/ | head ``` ### Step 3 ยท Check timing Identify where latency occurs. ``` curl -s -o /dev/null -w '%{http_code} dns=%{time_namelookup} total=%{time_total}\n' http://127.0.0.1/ ``` ## In practice, use it like this ### 1. Health check after deployment **Situation** โ€” Check that the service is healthy right after deployment. ``` for i in 1 2 3; do curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1/health; sleep 1; done ``` **Result** โ€” If 200 appears consistently, consider it healthy. **Point** โ€” If you add a health check to your deployment script, you can use it as an automatic rollback criterion. ### 2. Analyze response latency segments **Situation** โ€” External API calls are slow. ``` curl -s -o /dev/null -w 'dns=%{time_namelookup} conn=%{time_connect} tls=%{time_appconnect} total=%{time_total}\n' https://api.example.com/ ``` **Result** โ€” Break down DNS/TCP/TLS/overall time to find the bottleneck. **Point** โ€” If DNS is high, check the resolver; if TLS is high, check certificates/handshake. ## Points to note - In automation, omitting -m can cause an indefinite wait. - Use -k (ignore certificate) only for diagnostics and don't put it in production scripts. - Putting tokens/passwords on the command line leaves them in shell history. - Calls to external URLs can fail depending on proxy/firewall. ## Actual execution output The result of checking the health check status code, response time, and server headers. ![curl command output: HTTP status and response time](https://games.aidebatehub.com/assets/curl-demo.png) Production server --- Source (HTML): https://games.aidebatehub.com/programs/linux/network/curl.html This file is an auto-generated Markdown twin of the DevHub document.