aboutsummaryrefslogtreecommitdiff
path: root/example/api/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/api/reluax.luax
parent90d05fd9911596db33a20a164f92a51ffd067053 (diff)
example: add api and htmx example
Diffstat (limited to 'example/api/reluax.luax')
-rw-r--r--example/api/reluax.luax21
1 files changed, 21 insertions, 0 deletions
diff --git a/example/api/reluax.luax b/example/api/reluax.luax
new file mode 100644
index 0000000..cae3d33d
--- /dev/null
+++ b/example/api/reluax.luax
@@ -0,0 +1,21 @@
+local message = "default"
+
+local route = function(path, method, body)
+ if path ~= "/api/example" then
+ return 404, reluax.json { message = "Not Found" }
+ end
+
+ if method == "GET" then
+ return 200, reluax.json { message = message }
+ elseif method == "POST" then
+ message = body
+ return 200, reluax.json { message = message }
+ end
+
+ return 400, reluax.json { message = "Bad Request" }
+end
+
+return {
+ name = "api-example",
+ route = route
+}