Core API

Fundamental functions and objects available in the Lua environment.

The solidb Global

The solidb object is your main entry point for system interaction.

  • solidb.now() -> float
    Get current timestamp (seconds since epoch).
  • solidb.log(msg, level?)
    Log (info/warn/error) to server console.
  • solidb.uuid() -> string
    Generate a V4 UUID.
  • solidb.env(key) -> string
    Read permitted environment variable (must start with PUBLIC_).

HTTP Handling

When a script is called via HTTP, two global tables are available: request and response.

Request Object

{
  method = "POST",
  path = "/_api/script/myscript",
  headers = { ... },
  query = { page = "1" },
  body = { ... } -- Auto-parsed JSON
}
              

Response Helper

Return a table to send JSON automatically.

-- Simple return
return { success = true }

-- Custom Status
response.status = 201
response.headers["X-Custom"] = "Foo"
return { id = 123 }
              

Error Handling

Use standard Lua pcall or specific helpers to handle errors gracefully.

local status, err = pcall(function()
  error("Something went wrong")
end)

if not status then
  -- Log and return 500
  solidb.log(err, "error")
  response.status = 500
  return { error = err }
end

Throwing Errors

Using error() will stop execution and return a 500 Internal Server Error response with the message, unless caught.