aboutsummaryrefslogtreecommitdiff
path: root/example/htmx/reluax.luax
diff options
context:
space:
mode:
authorStanisław Zagórowski <hasohasacz@gmail.com>2024-01-19 22:38:58 +0100
committerStanisław Zagórowski <hasohasacz@gmail.com>2024-01-19 22:38:58 +0100
commitbae8d91990f7c1abb98b2b640513984a0e592db1 (patch)
tree6fafa6b2e78ea5fc2a1809c81f3984833a071c30 /example/htmx/reluax.luax
parent90d05fd9911596db33a20a164f92a51ffd067053 (diff)
example: add api and htmx example
Diffstat (limited to 'example/htmx/reluax.luax')
-rw-r--r--example/htmx/reluax.luax39
1 files changed, 39 insertions, 0 deletions
diff --git a/example/htmx/reluax.luax b/example/htmx/reluax.luax
new file mode 100644
index 0000000..8ab1cb8
--- /dev/null
+++ b/example/htmx/reluax.luax
@@ -0,0 +1,39 @@
+local page_wrapper = function(content)
+ return reluax.html_page(
+ <html>
+ <head>
+ <title>reluax</title>
+ <script src="https://unpkg.com/htmx.org@1.9.10"></script>
+ </head>
+ <body>
+ {$ content $}
+ </body>
+ </html>
+ )
+end
+
+local route = function(path, method, body)
+ if path == "/" and method == "GET" then
+ return 200, page_wrapper(
+ <div>
+ <h1>reluax</h1>
+ <p>Click the button to get a random number.</p>
+ <button hx-post="/random" hx-swap="outerHTML">Random</button>
+ </div>
+ )
+ elseif path == "/random" and method == "POST" then
+ return 200, reluax.html(<h3>{$ math.random(1, 100) $}</h3>)
+ end
+
+ return 404, page_wrapper(
+ <div>
+ <h1>reluax</h1>
+ <p>404 Not Found</p>
+ </div>
+ )
+end
+
+return {
+ name = "htmx-example",
+ route = route
+}