fetchlet 0.1.0

Rust-hosted JavaScript functions and Fetch handlers with explicit host services
Documentation

fetchlet

Embed a JavaScript runtime (QuickJS, Boa, or V8) inside Rust to call Fetch handlers and exported JavaScript functions with explicit permissions and resource limits.

cargo add fetchlet

Quick example

use std::num::NonZeroUsize;
use fetchlet::{App, Backend, Module, WorkerOptions};

let app = App::builder(Backend::quickjs())
    .module(Module::new(bundle))
    .spawn(WorkerOptions::new(NonZeroUsize::new(8).unwrap()))
    .await?;

let sum = app.call_json("add", &[20.into(), 22.into()]).await?;
let response = app.fetch(request).await?;
app.shutdown().await?;

For serving a web framework build directory over HTTP or inside a Tauri webview, use fetchlet-http.

Cargo features

Feature Adds
quickjs (default) Backend::quickjs(), Backend::QuickJs(QuickJsOptions)
boa Backend::boa(), Backend::Boa(BoaOptions)
v8 Backend::v8(), Backend::V8(V8Options)
process Process isolation per instance

Multiple engine features can be enabled together. Host Web API implementations are enabled by default via web-apis (url, url-pattern, compression, web-crypto, node-crypto).

V8 on Windows (MSVC)

When enabling v8 on Windows with MSVC, link against the static C runtime in .cargo/config.toml to match V8's prebuilt library:

[target.'cfg(all(windows, target_env = "msvc"))']
rustflags = ["-C", "target-feature=+crt-static"]

Documentation