A fetchlet application has two parts:
- JavaScript build — the
fetchletnpm package bundles your web framework’s server code and client assets into an artifact directory (build/). - Rust host — your Rust program loads that directory with
fetchletandfetchlet-httpand serves it over HTTP (or embeds it into a single binary).
This guide walks through SvelteKit and axum. For other frameworks, see Frameworks. To let a coding agent configure your project automatically, see Coding agents.
Prerequisites
- Node.js 20.19, 22.12, 24 or later (for building the JavaScript side)
- Rust 1.100 or later
A typical layout keeps the JavaScript app and Rust host side by side in the same project:
my-app/
├── package.json
├── vite.config.ts
├── src/ # SvelteKit app
├── build/ # fetchlet artifact (generated)
├── Cargo.toml
└── server/
└── main.rs # Rust host1. Build the artifact
In your JavaScript project, install fetchlet as a development dependency:
npm install -D fetchletpnpm add -D fetchletyarn add -D fetchletbun add --dev fetchletvp i -D fetchletConfigure the SvelteKit adapter in vite.config.ts:
// vite.config.ts
import { sveltekit } from "@sveltejs/kit/vite";
import fetchletAdapter from "fetchlet/sveltekit";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [sveltekit({ adapter: fetchletAdapter({ out: "build" }) })],
});Run your build command (for example, vite build). fetchlet writes build/ containing:
server.js— the bundled server entryfetchlet.json— manifest describing the handler, target engine, and requirementsclient/— static client assets
If you are not using Vite, use the fetchlet build command instead.
2. Serve it from Rust
Add the required crates to your Rust project. fetchlet enables the QuickJS engine by default; add --features boa or --features v8 to use another engine.
cargo add fetchlet
cargo add fetchlet-http --features axum
cargo add tokio --features macros,rt-multi-thread,net
cargo add anyhowStart a server that reads the build/ directory:
// server/main.rs
use fetchlet_http::Server;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await?;
println!("Listening on http://127.0.0.1:3000");
Server::new("build").serve(listener).await?;
Ok(())
}Run cargo run and open http://127.0.0.1:3000. Server serves client assets directly from Rust and forwards every other request to your framework.
You can also add Rust API routes, pass environment values and host services to JavaScript, and set resource limits on Server (Serving over HTTP).
3. Develop with live reload
During development, fetchlet dev watches your JavaScript sources, rebuilds the artifact on changes, and keeps the Rust server running with automatic browser reload.
Add a dev feature in Cargo.toml that enables fetchlet-http/dev-reload, then run:
npx fetchlet dev -- cargo run --features devpnpm exec fetchlet dev -- cargo run --features devyarn fetchlet dev -- cargo run --features devbunx fetchlet dev -- cargo run --features devvp exec fetchlet dev -- cargo run --features devFrameworks with Vite Environment API support can also run directly against vite dev without rebuilding (Development server).
4. Ship as a single binary
When you are ready to distribute your app, pack static assets into assets.flpk (assets: true in the adapter) and embed the build directory with fetchlet_http::include_artifact!. See Embedding and distribution.
Calling JavaScript without HTTP
You do not need an HTTP server to use fetchlet. fetchlet::App lets Rust invoke a Fetch handler directly or call any exported JavaScript function with Serde values (app.call("transform", &input)). See Running JavaScript.
Next steps
- Overview & choosing an engine: decide between QuickJS, Boa, and V8.
- Frameworks: adapter setup and request context for each framework.
- Development server: choose the best dev loop for your framework.
- Host services: pass environment values, Rust functions, and outbound fetch to JavaScript.
- Examples: runnable projects for every supported framework.