Manual · 7

Custom endpoints

Binds a script to its own HTTP route under /api/v1/scripts/*.

Configuration:

  • HTTP method (any).
  • Path pattern – fixed segments, named parameters (:id), and a trailing wildcard (*) are allowed, e.g. /orders/:id/status. If several registered patterns overlap for a request, the most specific one wins (literal before named parameter before wildcard).
  • Auth mode: public (reachable without logging in) or authenticated (a session or API token required).

The request object

The script has access to a global request object:

request.method   // "GET", "POST", ...
request.path     // the path that was called
request.params   // named path parameters, e.g. { id: "42" }
request.query    // query string parameters
request.headers  // HTTP headers
request.body     // parsed JSON, otherwise the raw text

The response

Either via the response object (chainable):

response.status(201).json({ ok: true });
// or: response.send("plain text");
// or: response.setHeader("X-Custom", "value");

Or simply the script’s last expression/return value – it’s then returned automatically as JSON, with no response.* call needed at all.