Skip to content

Fetch

Fetch bytes over HTTP from a URL — load a remote asset, pull a config or leaderboard. Client-side only in v1. Like persistence, it's asynchronous with a callback.

fetch

munos
fetch(url: string, cb, ctx: i32 = 0)
// cb(success: bool, data: u8[], ctx: i32)

The runtime validates the URL (HTTPS, with plain HTTP allowed only for localhost), consults an in-memory cache, applies concurrency and rate limits, then invokes your callback with the response body. On any failure the callback fires with success = false.

The callback slot takes a top-level function name or an inline literal, and you may declare any prefix of its parameters. The optional ctx: i32 is passed back unchanged — handy for routing one shared callback.

munos
fetch("https://cdn.example.com/sprites.png", got_sprites)

function got_sprites(success: bool, data: u8[]) {
    if !success { return }
    var sprite = image_from_png_bytes(data, 0, 0, 16, 16)
    // ...use it...
}

The error event

munos
event fetch_error(url: string, msg: string)

Fires in addition to the success = false callback when a fetch didn't deliver bytes (network error, non-2xx status, rejected scheme, rate-limit overflow, CORS denial). Declaring it is optional — failures remain visible through the callback's success = false. Client-only, since fetch itself is client-only in v1.

Server has no fetch

On the server, fetch is bound to a stub that always reports success = false. Outbound HTTP is a client capability in v1.

Part of the MultiNostalgia project.