Writing Cloudflare Workers entirely in Rust

Cloudflare has released worker, a Rust crate that lets developers build Workers without writing any JavaScript. The crate is available on GitHub and crates.io, and it runs on the V8 WebAssembly engine.

Previously, non-JS Workers required a "trampoline" layer to connect languages like Rust to JavaScript APIs such as fetch(). That approach meant substantial boilerplate, and off-the-shelf language bindings rarely included support for Cloudflare-specific services like KV and Durable Objects. While a starter template let developers pull Rust libraries into a JavaScript Worker, writing a full program in Rust and deploying it to the edge remained difficult.

The new worker crate removes the glue code and offers idiomatic Rust APIs for building Workers. It includes fetch, a router, HTTP utilities, KV stores, Durable Objects, secrets, and environment variables. The following snippet shows the crate’s ergonomic Rust-facing API:

use worker::*;

#[event(fetch)]
pub async fn main(req: Request, env: Env) -> Result<Response> {
    console_log!(
        "{} {}, located at: {:?}, within: {}",
        req.method().to_string(),
        req.path(),
        req.cf().coordinates().unwrap_or_default(),
        req.cf().region().unwrap_or("unknown region".into())
    );

    if !matches!(req.method(), Method::Post) {
        return Response::error("Method Not Allowed", 405);
    }

    if let Some(file) = req.form_data().await?.get("file") {
        return match file {
            FormEntry::File(buf) => {
                Response::ok(&format!("size = {}", buf.bytes().await?.len()))
            }
            _ => Response::error("`file` part of POST form must be a file", 400),
        };
    }

    Response::error("Bad Request", 400)
}

Scaffolding a new Rust Worker takes one command:

# see installation instructions for our `wrangler` CLI at https://github.com/cloudflare/wrangler
# (requires v1.19.2 or higher)
$ wrangler generate --type=rust my-project

The crate is open source, and Cloudflare is welcoming feedback and pull requests.

Why Rust first

Cloudflare’s push to simplify the Worker developer experience started with Rust for practical reasons. Rust has first-class WebAssembly support, a mature ecosystem, and a powerful macro system. Existing tooling such as wasm-bindgen and the web-sys crate provided a significant foundation. Rust is also widely used internally at Cloudflare, and its growing popularity made it a natural first target for native, non-JavaScript Workers.