The http module provides a scope-checked HTTP client: every request
is matched against the app's configured HttpScope allowlist before it is
dispatched, and out-of-scope URLs throw. Two entry points — fetch()
(one-shot response, with responseType: "text" | "json" | "binary" and
timeoutMs) and fetchStream() (streaming response: resolves as soon as
status + headers arrive, body chunks are pushed over a Channel into a
ReadableStream<Uint8Array>, so the app never buffers the whole
response). Everything is backed by the single plugin:http|fetch command
(aligned with @tauri-apps/plugin-http).
One command, one permission: http:allow-fetch (paired with
http:deny-fetch for explicit denial); the http:default set grants
fetch.
The scope comes from plugin construction: httpPlugin({ scope }), where
the allow array matches URLs by glob. From
examples/hello/src/main.ts:
Out-of-scope URLs (e.g. https://evil.example.com/steal) are rejected by
the backend with "scope denied" — the hello frontend asserts this
explicitly (HTTP_SCOPE_DENY_OK).
Example (adapted from sections 5b / 15 of
examples/hello/frontend/src/main.ts; the anchors HTTP_OK,
HTTP_SCOPE_DENY_OK, HTTP_STREAM_OK:6c/head1ms/total277ms are its real
run outputs):
timeoutMs maps to the backend's AbortSignal.timeout (P19); with
responseType: "binary" the response carries binary?: Uint8Array, and
"json" carries json?: unknown; request bodies may be a string,
Uint8Array/ArrayBuffer (base64 on the wire) or a plain object
(auto-serialized to JSON with an implicit content-type).
plugin:http|* totals 1 command:
| Command | API |
|---|---|
fetch |
fetch() (one-shot) and fetchStream() (streaming via a Channel) |
Full list in the Commands Reference and the API symbol reference.
Applicable version: ztron 0.3.1