From 0ce4f26f55c080a4dfa19f66ea3f5eeb533bb2c4 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2026 18:27:44 +0000 Subject: [PATCH 1/2] tinyweb: example usage hints print from the monitor's listening callback The auth, composition, sse, static and websocket examples printed their curl hints before tw_start, so they appeared even when the bind failed and named a hard-coded port. They now print from http.monitor's listening callback with the bound port, as example_app does (#3224). Each failure path prints the reason. From Jules task 7158961981082754066 (paul-hammant/aether-fork#43). Co-Authored-By: Claude Opus 5.5 --- contrib/tinyweb/example_auth.ae | 25 ++++++++++++++++--------- contrib/tinyweb/example_composition.ae | 26 +++++++++++++++----------- contrib/tinyweb/example_sse.ae | 16 +++++++++++++--- contrib/tinyweb/example_static.ae | 19 ++++++++++++++----- contrib/tinyweb/example_websocket.ae | 17 +++++++++++++---- 5 files changed, 71 insertions(+), 32 deletions(-) diff --git a/contrib/tinyweb/example_auth.ae b/contrib/tinyweb/example_auth.ae index 8d4f265c6..b8e8220b0 100644 --- a/contrib/tinyweb/example_auth.ae +++ b/contrib/tinyweb/example_auth.ae @@ -55,16 +55,23 @@ main() { } } - println("Starting server on localhost:8080...") - println("") - println("Test the auth flow:") - println(" curl http://localhost:8080/api/profile") - println(" -> 403 Try logging in again") - println("") - println(" curl -H 'Cookie: session=valid-session-abc' http://localhost:8080/api/profile") - println(" -> 200 User is logged in: alice@example.com") + http.monitor(tinyweb.http_server(server)) { + listening() |host: string, port: int| { + println("Test the auth flow:") + println(" curl http://localhost:${port}/api/profile") + println(" -> 403 Try logging in again") + println("") + println(" curl -H 'Cookie: session=valid-session-abc' http://localhost:${port}/api/profile") + println(" -> 200 User is logged in: alice@example.com") + println("\nPress Ctrl+C to stop.") + } + } + println("Starting server on localhost:8080...") result = tinyweb.tw_start(server) - if result != "" { println("ERROR: Failed to start server: ${result}") } + if result != "" { + println("ERROR: Failed to start server: ${result}") + } + tinyweb.tw_stop(server) } diff --git a/contrib/tinyweb/example_composition.ae b/contrib/tinyweb/example_composition.ae index ef1b03fad..d056dfaa5 100644 --- a/contrib/tinyweb/example_composition.ae +++ b/contrib/tinyweb/example_composition.ae @@ -75,19 +75,23 @@ main() { } } + http.monitor(tinyweb.http_server(server)) { + listening() |host: string, port: int| { + println("Server running! Try:") + println(" curl http://localhost:${port}/api/v1/health") + println(" curl http://localhost:${port}/api/v1/greeting/Jane/Doe") + println(" curl -H 'X-Admin-Token: secret42' http://localhost:${port}/admin/dashboard") + println(" curl http://localhost:${port}/admin/dashboard # -> 403") + println(" curl http://localhost:${port}/shop/catalog/products/99") + println(" curl http://localhost:${port}/extra/ping") + println("\nPress Ctrl+C to stop.") + } + } + println("Starting server on localhost:8080...") result = tinyweb.tw_start(server) - - if result == "" { - println("Server running! Try:") - println(" curl http://localhost:8080/api/v1/health") - println(" curl http://localhost:8080/api/v1/greeting/Jane/Doe") - println(" curl -H 'X-Admin-Token: secret42' http://localhost:8080/admin/dashboard") - println(" curl http://localhost:8080/admin/dashboard # -> 403") - println(" curl http://localhost:8080/shop/catalog/products/99") - println(" curl http://localhost:8080/extra/ping") - } else { - println("ERROR: Failed to start server") + if result != "" { + println("ERROR: Failed to start server: ${result}") } tinyweb.tw_stop(server) diff --git a/contrib/tinyweb/example_sse.ae b/contrib/tinyweb/example_sse.ae index 291ed2fe3..711babf1b 100644 --- a/contrib/tinyweb/example_sse.ae +++ b/contrib/tinyweb/example_sse.ae @@ -1,6 +1,7 @@ // Server-Sent Events (SSE) and chunked Example — streaming to browser clients import contrib.tinyweb +import std.http main() { println("=== TinyWeb SSE + Chunked Example ===\n") @@ -58,10 +59,19 @@ main() { } } - println("Open http://localhost:8080/ or: curl -N http://localhost:8080/sse/events") - println("Chunked: curl -N http://localhost:8080/countdown") + http.monitor(tinyweb.http_server(server)) { + listening() |host: string, port: int| { + println("Open http://localhost:${port}/ or: curl -N http://localhost:${port}/sse/events") + println("Chunked: curl -N http://localhost:${port}/countdown") + println("\nPress Ctrl+C to stop.") + } + } + println("Starting server on localhost:8080...") result = tinyweb.tw_start(server) - if result != "" { println("ERROR: Failed to start server: ${result}") } + if result != "" { + println("ERROR: Failed to start server: ${result}") + } + tinyweb.tw_stop(server) } diff --git a/contrib/tinyweb/example_static.ae b/contrib/tinyweb/example_static.ae index e18d75901..9f1b2ef40 100644 --- a/contrib/tinyweb/example_static.ae +++ b/contrib/tinyweb/example_static.ae @@ -36,12 +36,21 @@ main() { } } - println("Starting server on localhost:8080...") - println(" http://localhost:8080/ — index page") - println(" http://localhost:8080/static/... — static files from cwd") - println(" http://localhost:8080/api/health — JSON health check") + http.monitor(tinyweb.http_server(server)) { + listening() |host: string, port: int| { + println("Server running! Try:") + println(" http://localhost:${port}/ — index page") + println(" http://localhost:${port}/static/... — static files from cwd") + println(" http://localhost:${port}/api/health — JSON health check") + println("\nPress Ctrl+C to stop.") + } + } + println("Starting server on localhost:8080...") result = tinyweb.tw_start(server) - if result != "" { println("ERROR: Failed to start server: ${result}") } + if result != "" { + println("ERROR: Failed to start server: ${result}") + } + tinyweb.tw_stop(server) } diff --git a/contrib/tinyweb/example_websocket.ae b/contrib/tinyweb/example_websocket.ae index 36083946f..1eb89a40c 100644 --- a/contrib/tinyweb/example_websocket.ae +++ b/contrib/tinyweb/example_websocket.ae @@ -48,12 +48,21 @@ main() { } } - println("Open http://localhost:8080/ in a browser for the demo page.") - println(" ws://localhost:8080/echo — simple echo") - println(" ws://localhost:8080/foo/eee — echo x3") + http.monitor(tinyweb.http_server(server)) { + listening() |host: string, port: int| { + println("Open http://localhost:${port}/ in a browser for the demo page.") + println(" ws://localhost:${port}/echo — simple echo") + println(" ws://localhost:${port}/foo/eee — echo x3") + println("\nPress Ctrl+C to stop.") + } + } + println("Starting server on localhost:8080...") result = tinyweb.tw_start(server) - if result != "" { println("ERROR: Failed to start server: ${result}") } + if result != "" { + println("ERROR: Failed to start server: ${result}") + } + tinyweb.tw_stop(server) println("Server stopped.") } From f4ba5a87d731eefb1e9fe9c4efcd311d6c4e0538 Mon Sep 17 00:00:00 2001 From: Paul Hammant Date: Thu, 29 Oct 2026 18:39:02 +0000 Subject: [PATCH 2/2] tinyweb examples: changelog fragment Co-Authored-By: Claude Opus 5.5 --- .../20261029T183900Z-changed-tinyweb-example-hints.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 new_changelogs/20261029T183900Z-changed-tinyweb-example-hints.md diff --git a/new_changelogs/20261029T183900Z-changed-tinyweb-example-hints.md b/new_changelogs/20261029T183900Z-changed-tinyweb-example-hints.md new file mode 100644 index 000000000..afe680e8a --- /dev/null +++ b/new_changelogs/20261029T183900Z-changed-tinyweb-example-hints.md @@ -0,0 +1,6 @@ +- **The TinyWeb examples print their usage hints once the server is + listening.** `example_auth`, `example_composition`, `example_sse`, + `example_static` and `example_websocket` printed curl hints before + `tw_start`, so the hints appeared even when the bind failed, and named a + hard-coded port. They now print from `http.monitor`'s `listening` callback + with the bound port, as `example_app` does.