HttpService
Capability-gated asynchronous HTTP requests and cancellation.
Required setup
Section titled “Required setup”network.client; the native SDK supplies the HTTP transport. Your host’s address/port policy still applies.
The host is the program running your Luau code: normally the SDK’s native runner. Its provider/adapter implements an optional service. You do not need to write one to use a service already supplied by the SDK. Capabilities explains the manifest and remaining platform limits.
Example
Section titled “Example”This client fragment needs a running endpoint. The complete local HTTP recipe starts its own server and avoids a fixed port.
Where to put it: replace Src/Main.luau in a project created with this SDK. This is the complete entry file.
Project setup: add network.client to Capabilities in lui.json. See the capability guide.
local Window = Instance.new("Window", { Title = "LUI example", Size = UDim2.fromOffset(560, 280),})local Status = Instance.new("TextLabel", { Parent = Window, Text = "Ready", Position = UDim2.fromOffset(16, 170), Size = UDim2.new(1, -32, 0, 72),})local Button = Instance.new("TextButton", { Parent = Window, Text = "Try it", Size = UDim2.fromOffset(220, 44), Position = UDim2.fromOffset(16, 16),})Button.Text = "Request local status"Button.Activated:Connect(function() task.spawn(function() local Ok, Response = pcall(function() return app:GetService("HttpService"):RequestAsync({ Url = "http://127.0.0.1:8080/status", TimeoutMs = 3000, MaxResponseBytes = 4096, }) end) if not Ok then Status.Text = "Request could not complete"; return end Status.Text = "HTTP " .. Response.StatusCode .. ": " .. Response.Body end)end)Window.Visible = trueExpected result: With a local server on port 8080, pressing the button displays its status/body. Without one, it reports request failure without a dialog.
For source, manifest, pin and assets together, use the complete practical recipe.
Behavior and limits
Section titled “Behavior and limits”- HTTP methods yield: use task.spawn or task.defer. An event callback should schedule the task, rather than block the UI waiting for it.
- Handle both transport failure and a completed non-success HTTP status. The complete local HTTP recipe supplies a server as well as a client.
Methods
Section titled “Methods”RequestAsync
Section titled “RequestAsync”Makes an HTTP request from a yielding task. Returns HttpResponse for completed HTTP responses, including non-2xx statuses. Transport/policy failures raise errors; handle them with pcall.
RequestAsync(Options: HttpRequestOptions) -> HttpResponseGetAsync
Section titled “GetAsync”GET shorthand returning HttpResponse, not just its body string. Run it inside task.spawn or task.defer.
GetAsync(Url: string) -> HttpResponseCancelAll
Section titled “CancelAll”Cancels this runtime’s outstanding HTTP-client operations. It is not scoped to one library/client object; use it only when canceling all of them is intended.
CancelAll() -> ()Full type declaration — for type checking and deeper reference
The declaration is generated from the SDK. Self is supplied by a colon call; read means the field cannot be assigned. See how to read this reference.
export type HttpService = { read RequestAsync: (Self: HttpService, Options: HttpRequestOptions) -> HttpResponse, read GetAsync: (Self: HttpService, Url: string) -> HttpResponse, read CancelAll: (Self: HttpService) -> (),}Availability and deeper reading
Section titled “Availability and deeper reading”See platform limits before relying on host-specific behavior. The framework design specification and reflection/type sources are deeper engineering references, not extra setup required to build an app.