Skip to content

Response

Every handler and middleware receives the response as its second argument. All methods are chainable.

Method Description
res:status(code) Sets the status code (default 200)
res:header(name, value) Sets a response header
res:send(data) String → text/plain; table → JSON with application/json
res:json(data) Alias of send for tables
app:post("/items", function(req, res)
res:status(201)
:header("x-request-id", "abc123")
:json({ ok = true })
end)

send picks the Content-Type from the value you pass:

res:send("plain text") -- text/plain
res:send({ some = "table" }) -- application/json
res:json({ some = "table" }) -- application/json (alias)