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 |
Chaining
Section titled “Chaining”app:post("/items", function(req, res) res:status(201) :header("x-request-id", "abc123") :json({ ok = true })end)Content types
Section titled “Content types”send picks the Content-Type from the value you pass:
res:send("plain text") -- text/plainres:send({ some = "table" }) -- application/jsonres:json({ some = "table" }) -- application/json (alias)