From c59713cbd50cd46249c03664ced34bfed62c15f1 Mon Sep 17 00:00:00 2001 From: pgmtx Date: Sat, 16 May 2026 22:23:29 +0200 Subject: [PATCH 1/2] refact: port to Jule v0.2.1 --- examples/simpleDELETE/simpleDELETE.jule | 4 ++-- examples/simpleDownload/simpleDownload.jule | 4 ++-- examples/simpleGET/simpleGET.jule | 4 ++-- examples/simpleHEAD/simpleHEAD.jule | 2 +- examples/simplePOST/simplePOST.jule | 4 ++-- examples/simplePUT/simplePUT.jule | 4 ++-- snapbox.jule | 22 ++++++++++----------- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/simpleDELETE/simpleDELETE.jule b/examples/simpleDELETE/simpleDELETE.jule index accb3fd..af4b1bc 100644 --- a/examples/simpleDELETE/simpleDELETE.jule +++ b/examples/simpleDELETE/simpleDELETE.jule @@ -23,6 +23,6 @@ fn main() { fn handleStatus(code: status::StatusCode)! { if !status::IsSuccess(code) { - error(code) + throw code } -} \ No newline at end of file +} diff --git a/examples/simpleDownload/simpleDownload.jule b/examples/simpleDownload/simpleDownload.jule index f2fd45d..ffdd30c 100644 --- a/examples/simpleDownload/simpleDownload.jule +++ b/examples/simpleDownload/simpleDownload.jule @@ -7,7 +7,7 @@ use "example/snapbox" fn main() { - snapbox::Download("https://httpbin.org/get", "examples/bin/output.txt") else { + snapbox::Download("https://httpbin.org/get", "examples/output.txt") else { println(error) } -} \ No newline at end of file +} diff --git a/examples/simpleGET/simpleGET.jule b/examples/simpleGET/simpleGET.jule index 333543c..ace6bc1 100644 --- a/examples/simpleGET/simpleGET.jule +++ b/examples/simpleGET/simpleGET.jule @@ -23,6 +23,6 @@ fn main() { fn handleStatus(code: status::StatusCode)! { if !status::IsSuccess(code) { - error(code) + throw code } -} \ No newline at end of file +} diff --git a/examples/simpleHEAD/simpleHEAD.jule b/examples/simpleHEAD/simpleHEAD.jule index d152d89..1173383 100644 --- a/examples/simpleHEAD/simpleHEAD.jule +++ b/examples/simpleHEAD/simpleHEAD.jule @@ -19,4 +19,4 @@ fn main() { // body is always empty for HEAD println(response.status) -} \ No newline at end of file +} diff --git a/examples/simplePOST/simplePOST.jule b/examples/simplePOST/simplePOST.jule index f657b18..070b140 100644 --- a/examples/simplePOST/simplePOST.jule +++ b/examples/simplePOST/simplePOST.jule @@ -26,6 +26,6 @@ fn main() { fn handleStatus(code: status::StatusCode)! { if !status::IsSuccess(code) { - error(code) + throw code } -} \ No newline at end of file +} diff --git a/examples/simplePUT/simplePUT.jule b/examples/simplePUT/simplePUT.jule index 8ee8d66..bc95f3e 100644 --- a/examples/simplePUT/simplePUT.jule +++ b/examples/simplePUT/simplePUT.jule @@ -26,6 +26,6 @@ fn main() { fn handleStatus(code: status::StatusCode)! { if !status::IsSuccess(code) { - error(code) + throw code } -} \ No newline at end of file +} diff --git a/snapbox.jule b/snapbox.jule index bf6f02f..24c1df4 100644 --- a/snapbox.jule +++ b/snapbox.jule @@ -11,22 +11,22 @@ BSD 3-Clause License use "snapbox/header" use "snapbox/status" -cpp use "snapbox/internal/curlwrapper.hpp" +extern use "snapbox/internal/curlwrapper.hpp" #typedef -cpp struct Response { +extern struct Response { body: str status: status::StatusCode } /* args: url, headers, method */ -cpp fn request(str, []str, int): cpp.Response +extern fn request(str, []str, int): extern.Response /* args: url, data, headers, method */ -cpp fn post(str, str, []str, int): cpp.Response +extern fn post(str, str, []str, int): extern.Response /* args: url, path */ -cpp fn download(str, str): bool +extern fn download(str, str): bool // Request structure for non-data requests. struct Request { @@ -37,9 +37,9 @@ struct Request { impl Request { // Executes the request and returns the response. - fn Send(*self): cpp.Response { + fn Send(*self): extern.Response { headers := header::Slice(self.headers) - ret cpp.request(self.url, headers, self.method) + ret extern.request(self.url, headers, self.method) } // Sets headers for the request. @@ -59,9 +59,9 @@ struct DataRequest { impl DataRequest { // Executes the request and returns the response. - fn Send(*self): cpp.Response { + fn Send(*self): extern.Response { headers := header::Slice(self.headers) - ret cpp.post(self.url, self.data, headers, self.method) + ret extern.post(self.url, self.data, headers, self.method) } // Sets headers for the request. @@ -119,8 +119,8 @@ fn DELETE(url: str): DataRequest { // Uses the internal C++ function to download a file from the given URL and save it to the given path. fn Download(url: str, path: str)! { - response := cpp.download(url, path) + response := extern.download(url, path) if !response { panic("Download failed") } -} \ No newline at end of file +} From ef431a6577b0ca06d8a64b9613c4e77337de759b Mon Sep 17 00:00:00 2001 From: june Date: Sun, 17 May 2026 12:44:37 +0200 Subject: [PATCH 2/2] format changes --- examples/simpleDELETE/simpleDELETE.jule | 2 +- examples/simpleDownload/simpleDownload.jule | 2 +- examples/simpleGET/simpleGET.jule | 2 +- examples/simpleHEAD/simpleHEAD.jule | 2 +- examples/simplePOST/simplePOST.jule | 4 ++-- examples/simplePUT/simplePUT.jule | 4 ++-- header/_test.jule | 2 +- snapbox.jule | 12 ++++++------ 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/simpleDELETE/simpleDELETE.jule b/examples/simpleDELETE/simpleDELETE.jule index af4b1bc..9d61502 100644 --- a/examples/simpleDELETE/simpleDELETE.jule +++ b/examples/simpleDELETE/simpleDELETE.jule @@ -25,4 +25,4 @@ fn handleStatus(code: status::StatusCode)! { if !status::IsSuccess(code) { throw code } -} +} \ No newline at end of file diff --git a/examples/simpleDownload/simpleDownload.jule b/examples/simpleDownload/simpleDownload.jule index ffdd30c..4391a31 100644 --- a/examples/simpleDownload/simpleDownload.jule +++ b/examples/simpleDownload/simpleDownload.jule @@ -10,4 +10,4 @@ fn main() { snapbox::Download("https://httpbin.org/get", "examples/output.txt") else { println(error) } -} +} \ No newline at end of file diff --git a/examples/simpleGET/simpleGET.jule b/examples/simpleGET/simpleGET.jule index ace6bc1..2b198b6 100644 --- a/examples/simpleGET/simpleGET.jule +++ b/examples/simpleGET/simpleGET.jule @@ -25,4 +25,4 @@ fn handleStatus(code: status::StatusCode)! { if !status::IsSuccess(code) { throw code } -} +} \ No newline at end of file diff --git a/examples/simpleHEAD/simpleHEAD.jule b/examples/simpleHEAD/simpleHEAD.jule index 1173383..d152d89 100644 --- a/examples/simpleHEAD/simpleHEAD.jule +++ b/examples/simpleHEAD/simpleHEAD.jule @@ -19,4 +19,4 @@ fn main() { // body is always empty for HEAD println(response.status) -} +} \ No newline at end of file diff --git a/examples/simplePOST/simplePOST.jule b/examples/simplePOST/simplePOST.jule index 070b140..352f513 100644 --- a/examples/simplePOST/simplePOST.jule +++ b/examples/simplePOST/simplePOST.jule @@ -12,7 +12,7 @@ const DATA = "Hello, World!" fn main() { let headerMap: header::HeaderMap = { - header::ACCEPT: "application/json", + header::ACCEPT: "application/json", header::CONTENT_TYPE: "text/plain", } @@ -28,4 +28,4 @@ fn handleStatus(code: status::StatusCode)! { if !status::IsSuccess(code) { throw code } -} +} \ No newline at end of file diff --git a/examples/simplePUT/simplePUT.jule b/examples/simplePUT/simplePUT.jule index bc95f3e..7c78146 100644 --- a/examples/simplePUT/simplePUT.jule +++ b/examples/simplePUT/simplePUT.jule @@ -12,7 +12,7 @@ const DATA = "Puttin' on the Ritz..." fn main() { let headerMap: header::HeaderMap = { - header::ACCEPT: "application/json", + header::ACCEPT: "application/json", header::CONTENT_TYPE: "text/plain", } @@ -28,4 +28,4 @@ fn handleStatus(code: status::StatusCode)! { if !status::IsSuccess(code) { throw code } -} +} \ No newline at end of file diff --git a/header/_test.jule b/header/_test.jule index b435399..8982e62 100644 --- a/header/_test.jule +++ b/header/_test.jule @@ -12,7 +12,7 @@ use "std/testing" #test fn slicing(t: &testing::T) { let headerMap: HeaderMap = { - ACCEPT: "application/json", + ACCEPT: "application/json", USER_AGENT: "snapbox", } diff --git a/snapbox.jule b/snapbox.jule index 24c1df4..2bcaf42 100644 --- a/snapbox.jule +++ b/snapbox.jule @@ -80,7 +80,7 @@ impl DataRequest { // Builds a GET request object. fn GET(url: str): Request { ret Request{ - url: url, + url: url, method: 0, } } @@ -88,7 +88,7 @@ fn GET(url: str): Request { // Builds a HEAD request object. fn HEAD(url: str): Request { ret Request{ - url: url, + url: url, method: 1, } } @@ -96,7 +96,7 @@ fn HEAD(url: str): Request { // Builds a POST request object. fn POST(url: str): DataRequest { ret DataRequest{ - url: url, + url: url, method: 0, } } @@ -104,7 +104,7 @@ fn POST(url: str): DataRequest { // Builds a PUT request object. fn PUT(url: str): DataRequest { ret DataRequest{ - url: url, + url: url, method: 1, } } @@ -112,7 +112,7 @@ fn PUT(url: str): DataRequest { // Builds a DELETE request object. fn DELETE(url: str): DataRequest { ret DataRequest{ - url: url, + url: url, method: 2, } } @@ -123,4 +123,4 @@ fn Download(url: str, path: str)! { if !response { panic("Download failed") } -} +} \ No newline at end of file