AcediaDocumentation
Guides

HTTP and JSON

Check network results before decoding or using a response body.

Choose the response shape you need:

  • httpget returns only the body; failure becomes an empty string.
  • request returns Success, StatusCode, Body, and headers. Use it when status matters.

Fetch and decode JSON

The following helper keeps network and JSON errors separate:

local http = game:GetService("HttpService")

local function fetchJson(url)
    local response = request({
        Url = url,
        Method = "GET",
        Headers = { Accept = "application/json" },
    })

    if not response.Success then
        return nil, "Request failed with status " .. tostring(response.StatusCode)
    end

    local ok, value = pcall(function()
        return http:JSONDecode(response.Body)
    end)
    if not ok then
        return nil, "The response was not valid JSON"
    end

    return value
end

request yields until the operation finishes. A transport failure still produces a response record, with StatusCode set to 0; a server response outside the 2xx range sets Success to false. A successful HTTP status does not guarantee valid JSON, which is why decoding is protected separately.

Send JSON

Use HttpService:JSONEncode for the Body and set Headers["Content-Type"] to "application/json".

Header support: The current wrapper forwards only Content-Type, User-Agent, Accept, Authorization, Cookie, and Referer. Other custom header names are dropped. See request options for the exact fields.

On this page