Standard Library
HTTP: fetch & serve
fetch
fetch url [with { … }] performs an HTTP request. The optional with map supplies method, body, and headers.
summon res = fetch "https://api.github.com/users/torvalds"
proclaim extract "the 'name' field" from res
Outside
certain, fetch never touches the network — the oracle hallucinates a plausible response. Inside certain, it performs a real request and returns {status, headers, body}. A failed real request yields an oracle value.serve
serve <port> with <ritual> starts a REST server and keeps the process alive. The handler ritual is called once per request with a request map and returns a response.
| Request key | Value |
|---|---|
method | "GET", "POST", … |
path | the URL path, e.g. "/notes" |
query | a map of query-string parameters |
headers | a map of request headers |
body | the raw request body (text) |
json | the body parsed as JSON, or naught |
Return {status, body, headers?}. A text body stays text; a map/list is serialized to JSON. A bare value becomes a 200; an oracle value becomes a 500.
ritual handle(req) {
certain {
commune with "sqlite://./notes.db"
when req["method"] == "POST" and req["path"] == "/notes" -> {
inscribe req["json"] into notes
give {status: 201, body: {created: req["json"]}}
}
when req["method"] == "GET" and req["path"] == "/notes" ->
give {status: 200, body: recall "all" from notes}
}
when req["path"] == "/fortune" -> give {status: 200, body: divine "a techie fortune cookie"}
give {status: 404, body: {error: "not found"}}
}
serve 8787 with handle
Each request runs on an isolated fork of the evaluator, so concurrent requests can't leak zones or
/// context. Module-scope state is shared by design: top-level variables and DB connections (pooled by connection string) persist across requests — that's what makes a CRUD work.