From 44a9af54ece5bf9c9515cbb898d2f9bbab9af1c8 Mon Sep 17 00:00:00 2001 From: Jacob Haip Date: Thu, 23 Mar 2023 20:11:36 -0400 Subject: rework web wish to be return-value-oriented --- user-programs/folk-haip.local/web-endpoints.folk | 29 ++++++++++++------------ 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'user-programs') 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 "

Hello World!

" +Wish the web server handles route "/static-html/$" with handler { + return [$html "

Hello World!

"] } -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 "
    " + Wish the web server handles route "/regions/$" with handler [list Evaluator::tryRunInSerializedEnvironment { + set body "
      " foreach match $regionMatches { - append html "
    1. [dict get $match regionName]: [dict get $match region]
    2. " + append body "
    3. [dict get $match regionName]: [dict get $match region]
    4. " } - append html "
    " + append body "
" + 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 "

Hello Page Number $pageNumber

" - } +Wish the web server handles route {/pagee/(\d*)$} with handler { + if {[regexp -all {/pagee/(\d*)$} $path whole_match pageNumber]} { + return [$html "

Hello Page Number $pageNumber

"] + } } -- cgit v1.2.3