App → Route Handlers

Route Handlers

Register a handler for any HTTP-style method. Routes support typed params, wildcards, and optional Deflate compression per route.

Signatures

GET app:Get(route, handler, options?)
POST app:Post(route, handler, options?)
PUT app:Put(route, handler, options?)
DELETE app:Delete(route, handler, options?)

Parameters

ParameterTypeDescription
routestringRoute pattern. Supports typed params, wildcards, globs, and inline constraints. See Router.
handlerfunctionModern (req, res) or legacy (Player, Payload, req, res). Detected automatically by parameter count via debug.info.
options.compressboolean?Enable LZ77 Deflate on the response. GET and POST only. Default false.

Handler conventions

Use the modern (req, res) form — it gives you req.player and req.raw automatically. The legacy four-argument form is supported for backwards compatibility.

-- Modern (recommended)
app:Get("player/:id=number", function(req, res)
    res:Send({ id = req.params.id, name = req.player.Name })
end)

-- Legacy
app:Get("player/:id=number", function(Player, Payload, req, res)
    res:Send({ id = req.params.id })
end)

Method conventions

MethodBodyResponseNotes
GET optionalany data
POST requiredencoded data (Base64 / Deflate)
PUT requiredboolean? or niltable body warned and stripped
DELETEoptionalboolean? or niltable body warned and stripped

Compression

-- Deflate compression on a single route
app:Get("leaderboard", function(req, res)
    res:Send(bigLeaderboardTable)
end, { compress = true })

-- The client receives a compressed buffer; Network decompresses it automatically.
-- No API change needed on the client side.

See also

← App  ·  Middleware | run code before handlers  ·  Request Object | params, query, data  ·  Response Object | Send, Error, Status  ·  Router | full route pattern syntax  ·  Codec | compression internals