Request Methods
Four callback-based methods that each send a typed request to a server route and deliver the response to your function when it arrives.
Signatures
Parameters
| Parameter | Type | Description |
|---|---|---|
route | string | Route string matching a registered server handler — e.g. "player/123" or "shop/items?category=weapons" |
data | any? | Optional payload sent with the request. POST requires a body; PUT expects one. GET and DELETE accept optional data. |
callback | (res: NetworkResponse) → () | Called exactly once when the server responds or the request times out. |
Callback signature
The callback receives a single NetworkResponse table. Check res.type to branch on success vs error.
-- callback signature
function(res: NetworkResponse) → ()
-- res fields:
-- res.type "success" | "error" | "timeout"
-- res.status number? (HTTP-style code from res:Status() on server)
-- res.data any? (payload from res:Send(data) on server)
-- res.message string? (from res:Error(msg) or middleware rejection)
-- res.compressed boolean? (true if auto-decompressed from Deflate)
NetworkResponse fields
| Field | Type | Description |
|---|---|---|
type | "success" | "error" | "timeout" | Result classification. Always present. |
status | number? | HTTP-style status code set by res:Status() on the server. |
data | any? | Response payload from res:Send(data) on the server. |
message | string? | Error message from res:Error(message) or built-in middleware rejections. |
compressed | boolean? | true when the response was Deflate-compressed and was auto-decompressed client-side. |
Get
Fetches a resource from the server. Pass query-string parameters directly in the route string.
-- basic GET
network:Get("player/123", nil, function(res)
if res.type == "success" then
print(res.data.coins)
else
warn(res.message)
end
end)
-- with query string
network:Get("shop/items?category=weapons&page=1", nil, function(res)
populateShop(res.data)
end)
Post
Sends a body to create or submit data. The server handler receives the payload in req.data.
network:Post("player/123/update", { name = "NewName" }, function(res)
if res.type == "success" then
print("Saved", res.status)
end
end)
Put
Replaces or fully updates a resource. Semantically equivalent to HTTP PUT — the server overwrites with the body you send.
network:Put("inventory/slot/3", { itemId = 42, count = 1 }, function(res)
if res.type == "error" then
warn("Slot update failed:", res.message)
end
end)
Delete
Removes a resource. An optional body is supported but rarely needed.
network:Delete("party/invite/456", nil, function(res)
print("Invite removed, status:", res.status)
end)
Return value
Every method returns a requestId (number). Pass it to network:Cancel(requestId) to abort the request before the callback fires.
local id = network:Get("slow/resource", nil, function(res)
print(res.data)
end)
-- cancel if the player closes the menu before it resolves
closeButton.Activated:Connect(function()
network:Cancel(id)
end)
See also
← Network · Async / Promise API | chainable variants of the same methods · Cancel & Timeout | abort in-flight requests · App Route Handlers | server-side counterpart · NetworkResponse type | full field reference