Getting Started · 2 of 3

Hello, OxiScript

The smallest possible OxiScript procedure: takes a parameter, returns an object.

The procedure

proc hello(name) {
    return {greeting: "Hi, ", who: name}
}

Create it

{"cmd": "create_procedure",
 "script": "proc hello(name) { return {greeting: 'Hi, ', who: name} }"}

Response:

{"ok": true, "data": {"name": "hello"}}

Call it

{"cmd": "call_procedure", "name": "hello",
 "params": {"name": "Alice"}}

Response:

{"ok": true, "data": {"greeting": "Hi, ", "who": "Alice"}}

Variations

No parameters

proc heartbeat() {
    return {ok: true, time: "now"}
}

Multiple parameters

proc add_user(name, email, age) {
    return {created: true, name: name, email: email, age: age}
}

Returning a number

proc square(n) {
    return n * n
}

Returning an array

proc range3(start) {
    return [start, start + 1, start + 2]
}

Returning a boolean

proc is_adult(age) {
    return age >= 18
}

Returning null

proc do_nothing() {
    return null
}

Aborting instead of returning

proc reject() {
    abort "not implemented"
}

Calling reject returns {"ok": false, "error": "not implemented"}.

What just happened

  1. Your script was sent to the server as plain text.
  2. The lexer tokenized it; the parser built an AST; the compiler lowered it to JSON steps.
  3. Those steps were stored in the _procedures collection.
  4. On call_procedure, the procedure engine executed each step inside one OCC transaction.
Report Issue