The Desi Architect
Notes / Docker Sandboxes / HTTP and curl Cheat Sheet
Track 06 · Docker Sandboxes · Reference

HTTP and curl Cheat Sheet

Status codes, headers, Cache-Control values and the curl flags the labs use. Keep it open next to the HTTP, nginx, JWT and latency labs.

Free referenceKeep this tab open while you do a lab

00 /The shape of an HTTP conversation

GET /api/hello HTTP/1.1          <- request line: method, path, version
Host: example.com                <- request headers
Authorization: Bearer <token>

HTTP/1.1 200 OK                  <- response status line
Content-Type: application/json   <- response headers
Cache-Control: no-store

{"message": "hello"}             <- response body
MethodUsually means
GETRead something. Should not change anything.
POSTCreate something or run an action.
PUT / PATCHReplace or change something.
DELETERemove something.

01 /Status codes

CodeNamePlain meaning
200OKIt worked.
201CreatedIt worked and made something new.
301 / 302MovedGo to the address in the Location header.
304Not ModifiedYour saved copy is still good. No body sent.
400Bad RequestYour request was malformed.
401UnauthorizedI do not know who you are.
403ForbiddenI know who you are, and you may not do this.
404Not FoundNo such page.
429Too Many RequestsSlow down (a rate limit).
500Internal Server ErrorThe server broke.
502Bad GatewayA proxy got a bad answer from the app behind it.
503Service UnavailableThe server cannot help right now.
504Gateway TimeoutA proxy waited too long for the app behind it.

The first digit tells the story: 2 worked, 3 go somewhere else, 4 your request was wrong, 5 the server broke.

02 /Headers you will meet

HeaderMeaning
Content-TypeWhat the body is: application/json, text/html.
Content-LengthSize of the body in bytes.
Authorization: Bearer <token>Your proof of identity.
HostThe site name you asked for.
LocationWhere a redirect points.
ETagA fingerprint of the content. Send it back as If-None-Match to ask "changed?".
Cache-ControlWho may keep the answer and for how long.
X-Cache-StatusNot standard. Our nginx adds it to show HIT or MISS.

03 /Cache-Control values

ValueWhat it tells caches
max-age=3600Keep this for one hour.
no-storeDo not keep this at all.
no-cacheYou may keep it, but check with the origin before using it.
privateOnly the user's own browser may keep it. Shared caches (CDNs) must not.
publicAny cache may keep it.

04 /curl flags

FlagMeaningExample
-iShow the response headers too.curl -i http://127.0.0.1:18150/
-vShow the request and response, line by line.curl -v http://127.0.0.1:18081/price
-sSilent: no progress bar.curl -s http://127.0.0.1:18100/health
-X POSTChoose the method.curl -X POST http://127.0.0.1:18080/crash
-H "Name: value"Add a request header.curl -H "Authorization: Bearer abc" ...
-d '...'Send a request body.curl -d '{"username":"asha"}' ...
-o fileSave the body to a file.
-LFollow redirects.
--max-time 5Give up after 5 seconds.
-w "%{http_code}"Print the status code after the request.curl -s -o /dev/null -w "%{http_code}" URL
On Windows PowerShell

Type curl.exe, not curl. PowerShell has its own command named curl that behaves differently. When you send JSON, put a backslash before each inner double quote: -d '{\"username\":\"asha\"}'. In -H values with quotes, such as an ETag, do the same.

05 /DNS in one minute

WordMeaning
DNSTurns a name into an IP address.
A recordA name pointing to an IPv4 address.
TTLHow many seconds anyone may remember the answer.
NXDOMAINThe name does not exist.

Changing a DNS record does not change every customer at once. Each cache keeps the old answer until the TTL ends. That is why a failover through DNS can take as long as the TTL you set before the emergency.