Deriver API
HTTP/JSON reference — Introduction, Ontology, Inference, Deriver helpers.
Overview
deriver.app exposes small, purpose-built HTTP endpoints for the ontology UI and for rule inference. Server logic is implemented in PHP; structured responses use JSON (Content-Type: application/json; charset=utf-8). The Deriver and triple-list pages use JavaScript (fetch) to call these endpoints in the browser. Authentication follows the same session rules as the main app (signed-in admin vs. public knowledge bases where applicable).
Languages & data formats
- PHP — request handlers in
triple-list.php,rule-evaluate.php,deriver.php. - JSON — request bodies (
POSTwithphp://input) and JSON responses for APIs below. - JavaScript — client-side calls from
js/deriver-session.js,js/rule-network-viz.js, and inline scripts in the triple editor (e.g. predicate lookup modal). - HTML forms — triple and rule editors still use classic form posts for saves; those are not listed here as separate JSON APIs.
Flag preview
All ontology JSON helpers are on triple-list.php. Pass the active knowledge base with kb=<slug> (and session as required). Responses are JSON.
Resolves a flag image URL for language/locale cell l (editor preview).
Parameters (query)
kb— knowledge base slug (required).triple_list_flag_preview=1l— locale/language code (e.g.en).
GET triple-list.php?kb=my-kb&triple_list_flag_preview=1&l=en
// Example response
{"src":"…/flags/…svg"}
Enum lookup
Editor support for enumerated values (requires admin session and valid KB).
Parameters (query)
kbtriple_enum_lookup=1attreditor_l(optional)
GET triple-list.php?kb=my-kb&triple_enum_lookup=1&attr=…&editor_l=…
// Error / empty
{"ok":false,"message":"Nicht berechtigt"}
Predicate lookup
Returns predicate suggestions from the ontology for the triple editor (requires admin session).
GET triple-list.php?kb=my-kb&triple_p_lookup=1
// Shape (simplified)
{"ok":true,"values":[…]}
rule-evaluate.php (primary JSON API)
Method: POST only. Body: JSON. Evaluates a rule’s if_condition and processes then_action / else_action branches, returns prompts (ask, value), missing variables, or sync_all_if / admin actions.
POST rule-evaluate.php
Content-Type: application/json
{
"kb": "my-kb",
"rule_id": 42,
"variables": { "pages": "12", "SomeRule": "TRUE" },
"ui_lang": "en"
}
// Alternative: select by name
{ "kb": "my-kb", "rule_name": "My rule", "variables": {} }
sync_all_if
Jacobi-style IF sync over all rules in the KB (client sends current variables):
{ "kb": "my-kb", "action": "sync_all_if", "variables": { … } }
recompute_use_counts
Admin-only maintenance (recompute IF use counts):
{ "kb": "my-kb", "action": "recompute_use_counts" }
then_action / else_action — supported constructs
Action text is line-oriented (separated by newlines or ;). The engine recognises the following. Anything else on a line is currently ignored by the line processor (there is no send_mail() or similar in the codebase today).
set(varName, value)— assigns a variable.valuemay be a quoted string with$otherVar$placeholders, a variable name, a number, or a numeric expression using variable names (e.g.counter+1).age(argument)—argumentis a date string (Y-m-d) or a variable holding such a date. Setsage_valid(TRUE/FALSE),age_years,age_months,age_days.http_status(url)— resolvesurl(literal or variable), performs an HTTP HEAD request, setshttp_status(numeric code or empty),http_status_type, andhttp_status_description.ask(…)— handled by the evaluator (interactive prompts, optional scale / assign variable). Not executed as a simple assignment line.value("…")— firstvalue("…")in the chosen branch supplies free-text capture (ask_valueflow in JSON).
set(score, counter+1);
age($birthdate$);
http_status("https://example.com/api/health");
search_rules
These use query parameters on deriver.php (same KB context as the Deriver page).
Search rules (GET, JSON):
GET deriver.php?kb=my-kb&action=search_rules&q=invoice
// { "ok": true, "rules": [ { "id": "1", "name": "…" }, … ] }
deriver_save_session
Save Deriver session (POST, JSON body, admin):
POST deriver.php?kb=my-kb&action=deriver_save_session
{ "session_json": "{…}" }
deriver_load_last_session
Load last saved session (GET, admin):
GET deriver.php?kb=my-kb&action=deriver_load_last_session
// { "ok": true, "session_json": "…" } or null