neyuki 0.6.1

A small Lua-like scripting language implemented in Rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-- A small HTTP server with a few routes.

local http = require("@neyuki/http")

-- Visit http://127.0.0.1:8080/hello?name=you while this runs.
http.serve({ host = "127.0.0.1", port = 8080 }, function(request: Request): any
    local path, params = request:query()
    if (path == "/hello") then
        return "Hello, " .. (params.name ?? "stranger") .. "!\n"
    end
    if (path == "/echo") then
        return { headers = { ["content-type"] = request:header("content-type") ?? "text/plain" }, body = request.body }
    end
    return { status = 404, body = "No route for " .. request.method .. " " .. path .. "\n" }
end)