diff options
| author | Jacob Haip <jhaip@users.noreply.github.com> | 2023-03-24 00:11:36 +0000 |
|---|---|---|
| committer | Jacob Haip <jhaip@users.noreply.github.com> | 2023-03-24 00:11:36 +0000 |
| commit | 44a9af54ece5bf9c9515cbb898d2f9bbab9af1c8 (patch) | |
| tree | b88349083ce8e7f1e7f2e7662de69d6e04b2eac1 /user-programs | |
| parent | fix handling of web response with contentType and body (diff) | |
| download | folk-44a9af54ece5bf9c9515cbb898d2f9bbab9af1c8.tar.gz folk-44a9af54ece5bf9c9515cbb898d2f9bbab9af1c8.zip | |
rework web wish to be return-value-oriented
Diffstat (limited to 'user-programs')
| -rw-r--r-- | user-programs/folk-haip.local/web-endpoints.folk | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/user-programs/folk-haip.local/web-endpoints.folk b/user-programs/folk-haip.local/web-endpoints.folk index 274c350a..d9bd13e6 100644 --- a/user-programs/folk-haip.local/web-endpoints.folk +++ b/user-programs/folk-haip.local/web-endpoints.folk @@ -1,27 +1,28 @@ -Wish the Web server handles route "/static-html/$" with handler { - set html "<h1>Hello World!</h1>" +Wish the web server handles route "/static-html/$" with handler { + return [$html "<h1>Hello World!</h1>"] } -Wish the Web server handles route "/score/$" with handler { - set response [dict create contentType "application/json" body "{\"score\": 5}"] +Wish the web server handles route "/score/$" with handler { + return [$json "{\"score\": 5}"] } When the collected matches for [list /regionName/ has region /region/] are /regionMatches/ { - Wish the Web server handles route "/region/$" with handler [list Evaluator::tryRunInSerializedEnvironment { - set html "<ol>" + Wish the web server handles route "/regions/$" with handler [list Evaluator::tryRunInSerializedEnvironment { + set body "<ol>" foreach match $regionMatches { - append html "<li><strong>[dict get $match regionName]</strong>: [dict get $match region]</li>" + append body "<li><strong>[dict get $match regionName]</strong>: [dict get $match region]</li>" } - append html "</ol>" + append body "</ol>" + return [$html $body] } [Evaluator::serializeEnvironment]] } -Wish the Web server handles route "/redirect/$" with handler { - set response {raw "HTTP/1.1 302 Found\nLocation: https://folk.computer"} +Wish the web server handles route "/redirect/$" with handler { + return [dict create statusAndHeaders "HTTP/1.1 302 Found\nLocation: https://folk.computer"] } -Wish the Web server handles route {/pagee/(\d*)$} with handler { - if {[regexp -all {/pagee/(\d*)$} $path whole_match pageNumber]} { - set html "<h1>Hello Page Number $pageNumber</h1>" - } +Wish the web server handles route {/pagee/(\d*)$} with handler { + if {[regexp -all {/pagee/(\d*)$} $path whole_match pageNumber]} { + return [$html "<h1>Hello Page Number $pageNumber</h1>"] + } } |
