Ping vs cURL: Talking to Servers
- ping
- curl
- HTTP
- status codes
- ICMP
- debugging
- APIs
Ping vs cURL - Is It Up, and Is It Working? ๐ฐ๏ธ
4:55 PM, Friday. Slack lights up: "Is the API down?? Nothing's working!" Everyone panics. You calmly type two commands and, in 10 seconds, know exactly whose problem it is. That calm is a skill - here it is.
๐ง The mental model: a building
ping= knocking on the building's front door. Is anyone home? Is the building even standing? It tells you the machine is reachable - nothing about your app.curl= walking in and asking the receptionist a real question. Does the service actually answer correctly?
ping - "is the host reachable?" (Layer 3)
ping sends a tiny ICMP echo and times the round trip:
ping example.com
# 64 bytes from 93.184.216.34: time=12.3 ms โ
reachable, ~12 ms away
curl - "does the request actually work?" (Layer 7)
curl makes a real HTTP request and shows you the response - status, headers, body. This is how you test an API by hand:
curl -i https://example.com/health
# HTTP/2 200
# content-type: application/json
# {"status":"ok"}
๐ The killer insight: ping works but curl fails โ the server is up, but your app is broken (crashed service, wrong path, missing auth). That one distinction saves hours of blaming the network.
HTTP status codes - read them like an X-ray
The first digit tells you the whole story:
| Range | Meaning | The one-word version | Examples |
|---|---|---|---|
| 2xx | Success | "great" | 200 OK, 201 Created |
| 3xx | Redirect | "go look over there" | 301 Moved, 302 Found |
| 4xx | Client error | "YOU messed up" | 401 Unauthorized, 403 Forbidden, 404 Not Found |
| 5xx | Server error | "THEY messed up" | 500 Error, 503 Unavailable |
๐ง Remember just this: 4xx = YOU, 5xx = THEM. A 4xx means fix your request (bad URL, missing key, no auth). A 5xx means the server crashed - check its logs, not your code. (Fun one to cement it: 418 = "I'm a teapot", a real joke status code. If you remember the teapot, you remember 4xx = client.)
The curl flags you'll actually use
curl -i URL # -i = show response headers (and the status code)
curl -X POST URL # -X = choose the method (GET, POST, ...)
curl -H "Authorization: Bearer TOKEN" URL # -H = add a header (e.g. auth)
curl -d '{"qty":10}' URL # -d = send a request body (JSON)
๐ง Try it for real
ping google.com # ctrl-C to stop. See your latency.
curl -i https://api.github.com # a real public API - read the status line
Your Task
Write classify(status) to label any HTTP code by category, then print the classification for a few codes. Predict first: is 404 a "you" or "them" problem?