Skip to content

Search documentation

Enter at least two characters.

    HttpServer

    SDK 0.1.0-preview.2 · ExperimentalDownload & release notes ↗

    An owned HTTP server with explicit route registration, start and close operations.

    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.server 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 Server = app:GetService("HttpServerService"):CreateServer({Address = "loopback", Port = 0})
    Server:Route("GET", "/status", function(Request)
    return {StatusCode = 200, Headers = {{Name = "Content-Type", Value = "text/plain"}},
    Body = "Ready: " .. Request.Path}
    end)
    Server:Start()
    Status.Text = "Local URL: http://127.0.0.1:" .. Server.Port .. "/status"
    Window.Destroying:Connect(function() Server:Close() end)
    Window.Visible = true

    Expected result: Starts an HTTP endpoint on a free local-only port. Open the displayed URL on this machine to see Ready: /status.

    For source, manifest, pin and assets together, use the complete practical recipe.

    Actual bound port.

    Type: number. Read-only.

    Whether the server has started listening.

    Type: boolean. Read-only.

    Actual local address/port records.

    Type: {NetworkEndpoint}. Read-only.

    Registers a handler for an exact method and path before Start. Return HttpReplyOptions; keep work bounded. This is not an Express-style wildcard router.

    Route(Method: string, Path: string, Handler: (Request: HttpRequest) -> HttpReplyOptions) -> ()

    Starts serving after route registration.

    Start() -> ()

    Closes the server and cancels its pending request work. Independently spawned application tasks remain your responsibility.

    Close() -> ()
    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 HttpServer = {
    read Port: number,
    read IsListening: boolean,
    read BoundEndpoints: {NetworkEndpoint},
    read Route: (Self: HttpServer, Method: string, Path: string, Handler: (Request: HttpRequest) -> HttpReplyOptions) -> (),
    read Start: (Self: HttpServer) -> (),
    read Close: (Self: HttpServer) -> (),
    }

    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.