Skip to main content

HTTP API

The http table provides async HTTP client functions. Available in queries, procedures, and index hooks.

Methods

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?)

Options

The optional second argument is a table with:

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

Response

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)

Examples

-- 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)