App → Response Object

Response Object

The res argument for sending replies. Each terminal method (Send, Error, Redirect) is callable exactly once. Status is chainable and must precede a terminal call.

Methods

200 res:Send(data?)

Send a success response. data can be any table, string, number, or nil. For PUT/DELETE, only boolean? or nil is valid — passing a table is warned and stripped.

res:Send({ score = 100 })   -- sends data with 200
res:Send()              -- sends nil with 200 (e.g. after a PUT)
500 res:Error(message)

Send a 500 error response with a message string. The client receives the message in res.error.

if not valid then
    res:Error("item not found")
    return
end
res:Status(code) → res

Set an HTTP-style status code. Chainable — must be followed by a terminal call.

res:Status(204):Send()           -- no content
res:Status(403):Error("forbidden") -- custom 403
res:Redirect(path)

Re-dispatch the request to a different server route. Transparent to the client — the redirected handler sends the actual response. Version check, rate limit, and middleware run only once. Redirect chains are capped at 5 hops; a 508 is sent on overflow.

app:Get("me", function(req, res)
    -- transparently forward to the canonical route
    res:Redirect("player/" .. req.player.UserId)
end)

See also

← App  ·  Route Handlers | registering routes  ·  Request Object | params, query, data  ·  Network | how the client receives responses  ·  Types | NetworkResponse type definition