Skip to content
You are reading the HappyView v2 docs, which are no longer updated. Read the v3 docs.

HTTP API

The http table provides async HTTP client functions. Available in all Lua scripts — queries, procedures, and record/label scripts.

All methods take a URL and an optional options table, and return a response table.

http.get(url, opts?)
http.post(url, opts?)
http.put(url, opts?)
http.patch(url, opts?)
http.delete(url, opts?)
http.head(url, opts?)

The optional second argument is a table with:

FieldTypeDescription
headerstableRequest headers as key-value string pairs
bodystringRequest body (ignored for GET and HEAD)

Every method returns a table with:

FieldTypeDescription
statusintegerHTTP status code
bodystringResponse body text (empty string for HEAD)
headerstableResponse headers as key-value pairs (lowercase keys)
-- Simple GET
local resp = http.get("https://api.example.com/data")
-- resp.status = 200, resp.body = "...", resp.headers["content-type"] = "application/json"
-- GET with custom headers
local resp = http.get("https://api.example.com/data", {
headers = { ["authorization"] = "Bearer token123" }
})
-- POST with JSON body
local resp = http.post("https://api.example.com/hook", {
body = '{"key": "value"}',
headers = { ["content-type"] = "application/json" }
})
-- PUT, PATCH, DELETE, HEAD follow the same pattern
local resp = http.put(url, { body = data, headers = { ... } })
local resp = http.patch(url, { body = data, headers = { ... } })
local resp = http.delete(url, { headers = { ... } })
local resp = http.head(url)