From a2d705bfc20130f65c3ce21b0f027871c263f70e Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Thu, 1 Oct 2026 21:08:32 +0200 Subject: [PATCH] use echo platform for examples --- examples/body_bytes.roc | 9 +++------ examples/custom_method.roc | 7 ++----- examples/headers.roc | 7 ++----- examples/hello_request.roc | 7 ++----- examples/mock_send.roc | 7 ++----- examples/response.roc | 11 ++++------- examples/router.roc | 7 ++----- examples/tests.roc | 7 ++----- examples/timeouts.roc | 9 +++------ 9 files changed, 22 insertions(+), 49 deletions(-) diff --git a/examples/body_bytes.roc b/examples/body_bytes.roc index b6814a6..9f255e0 100644 --- a/examples/body_bytes.roc +++ b/examples/body_bytes.roc @@ -1,15 +1,12 @@ app [main!] { - pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/1.0.0/AnZoxzoGPtSGQ15EQh6pBeeaHJ7aizP9MQhK81dES3Uq.tar.zst", http: "../package/main.roc", } -import pf.Stdout import http.Method import http.Request import http.Response -main! : List(Str) => Try({}, [Exit(I32), StdoutErr(Str), ..]) -main! = |_args| { +main! = |_| { request = Request.from_method(POST) .with_uri("https://example.com/messages") .with_body("hello".to_utf8()) @@ -17,9 +14,9 @@ main! = |_args| { response = Response.from_status(201) .with_body("created".to_utf8()) - Stdout.line!("request body: ${Str.inspect(request.body())}")? + echo!("request body: ${Str.inspect(request.body())}\n") - Stdout.line!("response body: ${Str.inspect(response.body())}")? + echo!("response body: ${Str.inspect(response.body())}\n") Ok({}) } diff --git a/examples/custom_method.roc b/examples/custom_method.roc index 7f2e2bc..1b1cc1f 100644 --- a/examples/custom_method.roc +++ b/examples/custom_method.roc @@ -1,18 +1,15 @@ app [main!] { - pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/1.0.0/AnZoxzoGPtSGQ15EQh6pBeeaHJ7aizP9MQhK81dES3Uq.tar.zst", http: "../package/main.roc", } -import pf.Stdout import http.Method import http.Request -main! : List(Str) => Try({}, [Exit(I32), StdoutErr(Str), ..]) -main! = |_args| { +main! = |_| { request = Request.from_method(Unknown("PROPFIND")) .with_uri("https://dav.example.com/docs") - Stdout.line!("custom method: ${request.method_str()}")? + echo!("custom method: ${request.method_str()}\n") Ok({}) } diff --git a/examples/headers.roc b/examples/headers.roc index 1aaad66..8c62ceb 100644 --- a/examples/headers.roc +++ b/examples/headers.roc @@ -1,9 +1,7 @@ app [main!] { - pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/1.0.0/AnZoxzoGPtSGQ15EQh6pBeeaHJ7aizP9MQhK81dES3Uq.tar.zst", http: "../package/main.roc", } -import pf.Stdout import http.Method import http.Request @@ -17,8 +15,7 @@ ParsedHeaders : { parse_headers : Str -> Try(ParsedHeaders, [BadHeader, MissingRequiredField(Str)]) parse_headers = |raw| Encoding.HttpHeader.parse(raw) -main! : List(Str) => Try({}, [Exit(I32), StdoutErr(Str), ..]) -main! = |_args| { +main! = |_| { request = Request.from_method(GET) .with_uri("https://api.example.com/items") .with_headers([ @@ -27,7 +24,7 @@ main! = |_args| { { name: "X-Trace-Id", value: "demo-456" }, ]) - Stdout.line!(Str.inspect(request.headers()))? + echo!("${Str.inspect(request.headers())}\n") Ok({}) } diff --git a/examples/hello_request.roc b/examples/hello_request.roc index 1c0bed2..a4818fa 100644 --- a/examples/hello_request.roc +++ b/examples/hello_request.roc @@ -1,17 +1,14 @@ app [main!] { - pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/1.0.0/AnZoxzoGPtSGQ15EQh6pBeeaHJ7aizP9MQhK81dES3Uq.tar.zst", http: "../package/main.roc", } -import pf.Stdout import http.Method import http.Request -main! : List(Str) => Try({}, [Exit(I32), StdoutErr(Str), ..]) -main! = |_args| { +main! = |_| { request = Request.from_method(GET) .with_uri("https://example.com/widgets") - Stdout.line!("${request.method_str()} ${request.uri()}")? + echo!("${request.method_str()} ${request.uri()}\n") Ok({}) } diff --git a/examples/mock_send.roc b/examples/mock_send.roc index 97bc193..f84e255 100644 --- a/examples/mock_send.roc +++ b/examples/mock_send.roc @@ -1,9 +1,7 @@ app [main!] { - pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/1.0.0/AnZoxzoGPtSGQ15EQh6pBeeaHJ7aizP9MQhK81dES3Uq.tar.zst", http: "../package/main.roc", } -import pf.Stdout import http.Method import http.Request import http.Response @@ -18,14 +16,13 @@ mock_send = |request| Response.from_status(405) } -main! : List(Str) => Try({}, [Exit(I32), StdoutErr(Str), ..]) -main! = |_args| { +main! = |_| { request = Request.from_method(GET) .with_uri("https://example.com/offline") response = mock_send(request) - Stdout.line!("mock status: ${response.status().to_str()}")? + echo!("mock status: ${response.status().to_str()}\n") Ok({}) } diff --git a/examples/response.roc b/examples/response.roc index e02ae50..b2c89ce 100644 --- a/examples/response.roc +++ b/examples/response.roc @@ -1,20 +1,17 @@ app [main!] { - pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/1.0.0/AnZoxzoGPtSGQ15EQh6pBeeaHJ7aizP9MQhK81dES3Uq.tar.zst", http: "../package/main.roc", } -import pf.Stdout import http.Response -main! : List(Str) => Try({}, [Exit(I32), StdoutErr(Str), ..]) -main! = |_args| { +main! = |_| { response = Response.from_status(404) .add_header("Content-Type", "text/plain") .with_body("not found".to_utf8()) - Stdout.line!("status: ${response.status().to_str()}")? - Stdout.line!("headers: ${response.headers().len().to_str()}")? - Stdout.line!("body bytes: ${response.body().len().to_str()}")? + echo!("status: ${response.status().to_str()}\n") + echo!("headers: ${response.headers().len().to_str()}\n") + echo!("body bytes: ${response.body().len().to_str()}\n") Ok({}) } diff --git a/examples/router.roc b/examples/router.roc index 35841e5..c8cdbd3 100644 --- a/examples/router.roc +++ b/examples/router.roc @@ -1,9 +1,7 @@ app [main!] { - pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/1.0.0/AnZoxzoGPtSGQ15EQh6pBeeaHJ7aizP9MQhK81dES3Uq.tar.zst", http: "../package/main.roc", } -import pf.Stdout import http.Method import http.Request import http.Response @@ -111,15 +109,14 @@ route = |request| _ => json_error(404, "not found") } -main! : List(Str) => Try({}, [Exit(I32), StdoutErr(Str), ..]) -main! = |_args| { +main! = |_| { request = Request.from_method(POST) .with_uri("/widgets") .with_body("{\"name\":\"washer\",\"quantity\":5}".to_utf8()) response = route(request) - Stdout.line!("route status: ${response.status().to_str()} ${body_str(response)}")? + echo!("route status: ${response.status().to_str()} ${body_str(response)}\n") Ok({}) } diff --git a/examples/tests.roc b/examples/tests.roc index 993ec5d..7718213 100644 --- a/examples/tests.roc +++ b/examples/tests.roc @@ -1,17 +1,14 @@ app [main!] { - pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/1.0.0/AnZoxzoGPtSGQ15EQh6pBeeaHJ7aizP9MQhK81dES3Uq.tar.zst", http: "../package/main.roc", } -import pf.Stdout import http.Header import http.Method import http.Request import http.Response -main! : List(Str) => Try({}, [Exit(I32), StdoutErr(Str), ..]) -main! = |_args| { - Stdout.line!("Run `roc test examples/tests.roc` to exercise the http package examples.")? +main! = |_| { + echo!("Run `roc test examples/tests.roc` to exercise the http package examples.\n") Ok({}) } diff --git a/examples/timeouts.roc b/examples/timeouts.roc index 6388942..9b6c577 100644 --- a/examples/timeouts.roc +++ b/examples/timeouts.roc @@ -1,9 +1,7 @@ app [main!] { - pf: platform "https://github.com/lukewilliamboswell/roc-platform-template-zig/releases/download/1.0.0/AnZoxzoGPtSGQ15EQh6pBeeaHJ7aizP9MQhK81dES3Uq.tar.zst", http: "../package/main.roc", } -import pf.Stdout import http.Method import http.Request @@ -14,14 +12,13 @@ timeout_to_str = |request| TimeoutMilliseconds(ms) => "${ms.to_str()}ms" } -main! : List(Str) => Try({}, [Exit(I32), StdoutErr(Str), ..]) -main! = |_args| { +main! = |_| { no_timeout = Request.from_method(GET) .with_uri("https://example.com/stream") bounded = no_timeout.with_timeout(TimeoutMilliseconds(1500)) - Stdout.line!("default: ${timeout_to_str(no_timeout)}")? - Stdout.line!("bounded: ${timeout_to_str(bounded)}")? + echo!("default: ${timeout_to_str(no_timeout)}\n") + echo!("bounded: ${timeout_to_str(bounded)}\n") Ok({}) }