Lua Scripts Management

POST /_api/database/:db/scripts

Register a new Lua script.

Request Body Options

Field Type Description Required
name string Friendly name of the script. Yes
path string URL path segment (e.g. "greet"). Yes
methods array Allowed HTTP methods (["GET", "POST"]). Yes
code string The Lua source code. Yes
{"name": "Greeter", "path": "greet", "methods": ["GET"], "code": "return {msg='hi'}"}

Response

200 OK application/json
{ "id": "script_123", "name": "Greeter", "path": "greet", "status": "created" }
GET /_api/database/:db/scripts

List all registered scripts.

Response

200 OK application/json
{ "scripts": [ { "id": "script_123", "name": "Greeter", "path": "greet", "methods": ["GET"] } ] }
PUT /_api/database/:db/scripts/:id

Update an existing script.

DELETE /_api/database/:db/scripts/:id

Delete a script.

GET /_api/scripts/stats

Get script execution statistics.

Response

200 OK application/json
{ "total_executions": 1234, "total_errors": 5, "avg_execution_time_ms": 12.5, "scripts": [ { "path": "greet", "executions": 500, "errors": 1, "avg_time_ms": 8.2 } ] }
GET POST PUT DELETE /api/custom/:path

Execute a registered Lua script. The :path matches the script's registered path. Request body and query parameters are passed to the script.

Scripts handle their own authentication if needed. The response format depends on what the Lua script returns.

// Example: GET /api/custom/greet?name=Alice
// Calls the script registered with path "greet"

Response

200 OK application/json
// Response depends on script return value
{ "msg": "Hello, Alice!" }