-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.lua
More file actions
29 lines (22 loc) · 737 Bytes
/
example.lua
File metadata and controls
29 lines (22 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- !strict
route("/", function(req, res)
local x = "world"
-- Create response body
local response_body = "hello, " .. x .. ", you called from " .. req.path .. ", status: " .. res.status .. ", method: " ..
req.method .. ", protocol: " .. req.protocol
-- Add body if method is POST
if req.method == "POST" then
response_body = response_body .. ", body: " .. req.body
end
-- Set status so we can test if it works!
res.status = 299
return response_body
end)
route("/battery-level", function(req, res)
local level = getBatteryLevel()
if level then
return "Battery level: " .. level .. "%"
else
return "Could not get battery level :("
end
end)