mangle-server
HTTP server for evaluating Mangle programs. Wraps the Rust mangle-driver compilation and execution pipeline behind a JSON API.
Usage
Options
| Flag | Default | Description |
|---|---|---|
--port <PORT> |
8090 |
Port to listen on |
--programs-dir <DIR> |
none | Directory of .mg files to load on startup (program name = file stem) |
Example
# Start with pre-loaded programs
API
All endpoints accept and return application/json. On error, the response body is { "error": "<message>" } with an appropriate HTTP status code (400, 404, or 500).
POST /programs
Load a named program. The source is compiled to extract predicate names and stored for later querying.
Response:
GET /programs
List all loaded programs and their predicates.
Response:
POST /query
Query a relation from a loaded program. The program is recompiled and executed on each query.
Response:
The query string must be a valid Mangle atom (e.g. predicate(X, Y)). The predicate name is extracted to determine which relation to scan. All tuples from that relation are returned.
POST /eval
Compile and execute ephemeral source without storing it. Useful for one-off evaluation.
Response:
If query is omitted, all derived facts across all relations are returned.
Value encoding
Mangle values map to JSON as follows:
| Mangle | JSON | Example |
|---|---|---|
Value::Number(n) |
number | 42 |
Value::String(s) |
string | "hello" |
Value::Null |
null | null |
Result tuples are returned as arrays of arrays: [[val, ...], ...].
Mangle syntax notes
String constants in Mangle source must be double-quoted: greeting("hello"), not greeting(hello). Unquoted lowercase identifiers are not valid constant syntax. Numbers are unquoted: p(1, 2). Variables start with an uppercase letter: q(X) :- p(X).
Container image
A Containerfile is provided for building with Podman:
Pass arguments after the image name: