Before you start
You need a Wapka site with the Lua engine enabled. Create one or switch an existing site:
- Go to your site overview → Site Settings
- Under Engine, select Lua Engine
- Scroll down to lua_init — this is where your script lives
Hello Wapka
Paste this into lua_init and click Save:
local app = framework()
app:get("/", function(ctx)
return { message = "Hello, Wapka!" }
end)
Open your site in a browser. You'll see:
{ "message": "Hello, Wapka!" }
You just built a JSON API in 4 lines. No server setup, no deployment pipeline, no configuration.
Adding a second route
local app = framework()
app:get("/", function(ctx)
return { message = "Home page" }
end)
app:get("/about", function(ctx)
return {
title = "About Us",
team = { "Alice", "Bob", "Charlie" },
founded = 2024
}
end)
Visit /about — you'll see the team data as JSON.
Understanding what happened
framework()created your appapp:get("/", handler)said "when someone visits/, run this function"- Your handler returned a Lua table — Wapka automatically converted it to JSON
- The response was sent with
Content-Type: application/json
No routing config file. No web server setup. Just Lua.
What can a handler return?
| You return | Wapka sends |
|---|---|
A table { key = "value" } |
JSON with correct headers |
A string "Hello" |
Plain text or HTML |
A number 404 |
That HTTP status code |
ctx:render("page", data) |
Rendered HTML template |
ctx:redirect("/url") |
HTTP redirect |
Debugging
Stuck? Use print() and dump():
app:get("/debug", function(ctx)
print("Someone visited /debug")
dump(req.headers) -- see all request headers
dump(env) -- see environment info
return { ok = true }
end)
In debug mode (APP_DEBUG=true), the output appears in the response. In production, it's silently discarded.
Where to go from here
| You want to | Read |
|---|---|
| Understand all globals | Globals Reference |
| Handle URL patterns | Routing |
| Render HTML pages | Twig Overview |
| Store and query data | API Library |
Tip: You can edit
lua_initanytime. Changes go live immediately — no restart needed.