k.KAWAKIDOCSBack to site
Documentation menu

KAWAKI DOCS / LUA · GAME

Markdown

http

Requests never block the game: the callback fires later on the client thread with a response table, or with nil and an error message when the request fails at the network level (an HTTP error status is still a response — check ok). Callbacks of an unloaded script are dropped.

Function Does
http.get(url, callback[, headers]) GET request
http.post(url, body, callback[, headers]) POST request with a string body
http.request(opts, callback) Any method: opts = { url, method, body, headers, timeout }

timeout is in seconds (default 10). Redirects are followed.

Response

Field Value
status HTTP status code
ok true for 2xx
body Response body as a string
headers Table of lowercased header names; repeated values joined with ,
http.get("https://api.mojang.com/users/profiles/minecraft/Notch", function(res, err)
    if not res then
        kawaki.log("request failed: " .. err)
    elseif res.ok then
        kawaki.log(res.body)
    end
end)

http.request({
    url = "https://example.com/hook",
    method = "PUT",
    body = '{"hello":"world"}',
    headers = { ["Content-Type"] = "application/json" },
}, function(res) end)