Checking a service
A lamp in your base that lights up when your favourite web site is down, and a display that tells why. And for the curious: asking a server which methods it allows, and what a request looks like when it arrives.
Functions: HTTP_HEAD, HTTP_OPTIONS, HTTP_TRACE, and FROM_JSON of c0de/strings
What you need
The mod c0de net in your game. For the status lamp: a timer block, a comparator and a redstone lamp, a display wall of 2 × 1 display blocks, and optionally variable items server and endpoint of type STRING to check another site than c0de.at. For what a server allows: a trigger block with a button, a laptop and two uninitialized variable items. For the exercises: a redstone torch and a second redstone lamp.
The idea
To see if a site is up, you don't need the whole page. HTTP_HEAD asks like GET, but the server sends only the headers of its answer: the status, the type, the date of the last change. That's quick and costs the server almost nothing, so a timer block can ask every minute.
The program tells the world through its exit code: 0 if the site answered, 1 if it answered with an error status like 404 or 503, 2 if there was no answer at all. A comparator next to the timer block turns the exit code into a redstone signal, and the lamp lights whenever it isn't 0.
HTTP_OPTIONS and HTTP_TRACE are tools for finding out about a server: OPTIONS asks which methods an endpoint allows, TRACE asks the server to send back the request as it arrived.
The program
PROGRAM statuslamp
NOOP
INCLUDE c0de/strings
INCLUDE c0de_net/http
NOOP
STRUCT page
BEGIN
type STRING TAG(json: "content-type")
changed STRING TAG(json: "last-modified")
END STRUCT
NOOP
FUNCTION check
PARAMETER server STRING "c0de.at"
PARAMETER endpoint STRING "/"
BEGIN
VARIABLE status INTEGER
VARIABLE api STRUCT c0de_net/http/HTTP_CONNECTION
VARIABLE problem ERROR
VARIABLE answer STRING
VARIABLE info STRUCT page
ASSIGN api.use_ssl TRUE ;
ASSIGN api.server server ;
ASSIGN api.timeout 5 ;
CALL c0de_net/http/HTTP_HEAD problem
PARAMETER connection api ;
PARAMETER endpoint endpoint ;
RESULT result answer
RESULT status status
CALL CLS
CALL PRINT
PARAMETER value server ⊕ endpoint ;
IF problem.code ≠ 0 AND problem.code ≠ c0de_net/http/HTTP_STATUS ;
BEGIN
CALL PRINT
PARAMETER value "DOWN: " ⊕ problem.message ;
EXIT 2 ;
END IF
CALL c0de/strings/FROM_JSON
PARAMETER source answer ;
PARAMETER destination info ;
CALL PRINT
PARAMETER value "Status " ⊕ status ;
CALL PRINT
PARAMETER value info.type ;
CALL PRINT
PARAMETER value info.changed ;
IF problem.code = c0de_net/http/HTTP_STATUS ;
BEGIN
EXIT 1 ;
END IF
END FUNCTIONBuilding and running it
- Place the timer block, a comparator facing away from it, and the redstone lamp in front of the comparator.
- Bind the display wall to
statuslamp/check. - Set the timer block to
statuslamp/checkand an interval of 1200 ticks (one minute). Put in the itemsserverandendpointif you want to check another site.
The wall shows the site and its answer, and the lamp stays dark:
c0de.at/
Status 200
text/html; charset=utf-8
Thu, 12 Nov 2026 07:28:38 GMT
With the endpoint /api/nothing, the wall shows Status 404 and application/json; charset=utf-8, and the lamp lights with signal strength 1. For a server that doesn't exist, it shows DOWN: and the reason, and the signal is 2.
Nobody starts the process of a timer block, so the requests come from the computer of its owner. If the owner is offline, the request fails with CLIENT_UNAVAILABLE, and the lamp lights too – the program can't tell whether the site is down or nobody can ask. The same happens if the owner has switched requests off on their computer.
How it works
- HEAD returns the headers twice.
headersis a HASH, andresult– for HEAD only – is the same headers as a JSON object, like{"content-type":"text/html; charset=utf-8","last-modified":"…",…}. FROM_JSON reads it into the structpage, whose tags pick the two headers the program shows. A header that is missing leaves its element empty. - The error decides the exit code. The CALL catches every error in
problem. The codec0de_net/http/HTTP_STATUS(1000) means the server answered with a status of 400 or higher – it's up, but something is wrong. Every other code means there was no answer to read, and the program shows the message, like an unknown host, and ends withEXIT 2. - EXIT is the signal.
EXIT 1andEXIT 2end the process with that code. Without an EXIT, the function ends normally with code 0. - Short timeout.
timeout5 means: a site that takes longer than five seconds counts as down.
What a server allows
This program asks the to-do list of c0de.at (see Talking to a REST service) what it allows, and then tries TRACE on it:
PROGRAM methodcheck
NOOP
INCLUDE c0de/strings
INCLUDE c0de_net/http
NOOP
STRUCT request
BEGIN
method STRING
path STRING
END STRUCT
NOOP
FUNCTION ask
PARAMETER endpoint STRING "/api/tutorial/todo"
RESULT methods STRING
RESULT traced INTEGER
BEGIN
VARIABLE api STRUCT c0de_net/http/HTTP_CONNECTION
VARIABLE problem ERROR
VARIABLE headers HASH STRING
VARIABLE answer STRING
VARIABLE seen STRUCT request
VARIABLE known BOOLEAN
ASSIGN api.use_ssl TRUE ;
ASSIGN api.server "c0de.at" ;
ASSIGN api.timeout 10 ;
CALL c0de_net/http/HTTP_OPTIONS
PARAMETER connection api ;
PARAMETER endpoint endpoint ;
RESULT headers headers
CALL HAS_KEY
PARAMETER hash headers ;
PARAMETER key "allow" ;
RESULT result known
ASSIGN methods "unknown" ;
IF known ;
BEGIN
ASSIGN methods headers["allow"] ;
END IF
CALL CLS
CALL PRINT
PARAMETER value "Allowed: " ⊕ methods ;
CALL c0de_net/http/HTTP_TRACE problem
PARAMETER connection api ;
PARAMETER endpoint endpoint ;
RESULT result answer
RESULT status traced
IF problem.code = c0de_net/http/HTTP_STATUS ;
BEGIN
CALL PRINT
PARAMETER value "TRACE refused: " ⊕ problem.message ;
RETURN
END IF
CALL c0de/strings/FROM_JSON
PARAMETER source answer ;
PARAMETER destination seen ;
CALL PRINT
PARAMETER value "TRACE arrived as " ⊕ seen.method ⊕ " " ⊕ seen.path ;
END FUNCTIONBind a laptop to methodcheck / ask. Set the trigger block to methodcheck / ask, put in two uninitialized variable items for the results methods and traced, and press the button. The laptop shows:
Allowed: GET, HEAD, POST, OPTIONS
TRACE refused: 405 Method Not Allowed- OPTIONS answers in the header
allow. Not every server sends it, so HAS_KEY checks first; a missing key would raise UNKNOWN_KEY. - TRACE is often refused. It's not in the list, so the server answers 405, and HTTP_TRACE raises HTTP_STATUS. The program catches it and shows the message instead of crashing.
traced, the status, is 405. - A server that allows TRACE sends the request back; the program reads its method and path. Many servers don't, because the echo could reveal headers like cookies. c0de.at doesn't either: try the endpoint
/api/tutorial/echo, which answers every method – OPTIONS lists TRACE there, but the web server in front of it refuses TRACE with 405 before the request reaches the echo. That is what TRACE is for: seeing what the machines between you and the service do with a request.
Try it yourself
- Check several sites with one timer block and show each on its own line. The exit code is the number of sites that don't answer.
Solution
PROGRAM statusboard
NOOP
INCLUDE c0de_net/http
NOOP
VARIABLE servers ARRAY STRING
BEGIN
"c0de.at" "api.open-meteo.com"
END VARIABLE
NOOP
FUNCTION checkAll
BEGIN
VARIABLE down INTEGER
VARIABLE api STRUCT c0de_net/http/HTTP_CONNECTION
VARIABLE problem ERROR
ASSIGN api.use_ssl TRUE ;
ASSIGN api.timeout 5 ;
CALL CLS
EACH server servers
BEGIN
ASSIGN api.server server ;
CALL c0de_net/http/HTTP_HEAD problem
PARAMETER connection api ;
IF problem.code = 0 OR problem.code = c0de_net/http/HTTP_STATUS ;
BEGIN
CALL PRINT
PARAMETER value server ⊕ ": up" ;
END
ELSE
BEGIN
CALL PRINT
PARAMETER value server ⊕ ": DOWN" ;
ASSIGN down down + 1 ;
END IF
END EACH
EXIT down ;
END FUNCTIONThe servers are an array, and EACH asks one after the other, with the same connection and a new server. Here a site counts as up if it answers at all, also with an error status: api.open-meteo.com answers 404 for /, but it is there. With two sites down, the lamp gets signal strength 2.
- Add a second lamp that lights while the site is up.
Solution
Put a redstone torch on the side of a block that the comparator powers, and the second lamp next to the torch. The torch inverts the signal: it is on while the comparator is off, that is while the exit code is 0. The program doesn't change.