Linux Labs

Networking / Stage 6 of 14

From connection to application response

Not running Starting usually ~20 s
Leave the lesson

Step 3 of 7 · on a machine · 5 min

The answer's status and curl's code

The third complaint reached a program, and it answered not-ready. Two different numbers tell whether such an answer counts as success.

An HTTP answer starts with a status, a three-digit number: 200 — done, 404 — no such page, 503 — the service is temporarily not ready. The -w 'http=%{http_code}\n' option asks curl to print the status after the answer.

The command itself has a result of its own, the exit code: 0 means success, any other number an error. echo $? prints it right after the command; the next command overwrites it.

Exercise · look

A 503 answer through curl's eyes

Request /health from the client without -f, printing the status, then with -f. Right after each curl, run echo $?.

First, predict

The server answered /health with status 503. What will the first echo $?, after curl without -f, print?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Ubuntu 24.04
Loading…