Rust and Go API routes are in public beta.
Farm.js now serves route.rs and route.go next to route.ts through the experimental Polyroute plugin. How to try it, how it works, what the numbers say, and what the beta does not do yet.
In this article 4 sections
Rust and Go API routes are in public beta
KinfeMichael Tariku · Nov 2026
You have a Rust parser that already works. Or a Go function your team has trusted for years. You want it behind /api/parse in your Farm.js app.
Until now that meant a rewrite in TypeScript, or a second service and a network hop to reach it.
Farm.js now serves route.rs and route.go next to route.ts, through the experimental Polyroute plugin. You write the handler in Rust or Go, put it where a TypeScript route would go, and Farm.js routes requests to it with the same URL rules and middleware.
This is a public beta. The feature is opt-in, the API can still change, and the verified surface is small. The rest of this post covers what that surface is, what it costs, and when it's faster.
Try it
Install the Farm.js beta and Polyroute. The machine that builds the app needs a toolchain for each language you use. The machine that runs the build needs only Node.
pnpm add @farm.js/core@beta
pnpm add -D @farm.js/cli@beta @farming-labs/polyroute@beta
# Rust routes
rustup target add wasm32-wasip2
# Go routes need Go 1.27.1 or newer
Register Polyroute once, as an ordinary Vite plugin:
// farm.config.ts
import { defineConfig } from "@farm.js/core";
import { polyroute } from "@farming-labs/polyroute";
export default defineConfig({
vite: { plugins: [polyroute()] },
});
Then put routes where you'd put any other route:
src/app/api/
hello/route.ts → /api/hello
primes/route.rs → /api/primes
slug/route.go → /api/slug
go.mod
go.sum
A Go route is a main package with its own module. It registers a standard net/http handler:
// src/app/api/slug/route.go
package main
import (
"encoding/json"
"net/http"
"strings"
"unicode"
"go.bytecodealliance.org/wasi/wasihttp"
)
// slugify lowercases text and joins its letter and digit runs with dashes.
func slugify(text string) string {
words := strings.FieldsFunc(strings.ToLower(text), func(r rune) bool {
return !unicode.IsLetter(r) && !unicode.IsDigit(r)
})
return strings.Join(words, "-")
}
func init() {
wasihttp.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
w.Header().Set("allow", "GET")
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
text := r.URL.Query().Get("text")
w.Header().Set("content-type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"text": text, "slug": slugify(text)})
})
}
func main() {}
Copy its go.mod and go.sum from Polyroute's slug example. The first build downloads the route's Go modules. Only route.go defines the URL; other .go files in that folder are part of the same route.
The Rust route is an async function that receives the request and answers it. The prime-counting example counts the primes below limit.
Start the dev server and call both:
farm dev
curl "localhost:3000/api/slug?text=Hello%20Farm"
# {"slug":"hello-farm","text":"Hello Farm"}
curl "localhost:3000/api/primes?limit=10"
# {"limit":10,"primes":4}
Edit route.go and the next request runs the new code, without a restart. Delete it and /api/slug returns 404. For production, build the Node server and deploy the whole output:
farm build --preset node-server
The handler decides which methods it accepts. A POST to /api/slug gets a 405 with allow: GET. Call these routes with fetch; Farm.js's typed API client can't infer a Rust or Go schema.
How it works
Polyroute owns the languages. At build time it runs each route's own toolchain: cargo with the wasm32-wasip2 target for Rust, componentize-go for Go. The result is a WebAssembly binary, not a native one, so the same file runs on any operating system and CPU that runs Node. Polyroute then generates the JavaScript that loads it and hands Farm.js a module that exports ordinary Fetch handlers: a web Request in, a Response out.
Farm.js owns everything around it. It discovers route.rs and route.go in src/app/api, matches the URL, and runs your middleware. Then it calls the handler the same way it calls a TypeScript one. There's no second server and no network hop between Farm.js and your Rust or Go code.
The binaries ship inside the server output, in polyroute/<hash>/ beside the JavaScript that loads them, and never in the public folder. At run time Node's V8 engine compiles the WebAssembly to machine code and runs it in the same process as your TypeScript routes, so the server needs Node and nothing else: no Rust or Go toolchain. Remove the plugin and Farm.js stops discovering these files. Apps without Polyroute install no compiler and scan only TypeScript and JavaScript routes, as before.
Polyroute also has an experimental second runtime. With polyroute({ experimental: { runtime: "wasmtime" } }), the build goes one step further and compiles each route ahead of time to machine code, and the server runs it in wasmtime through a Node add-on instead of V8. In Polyroute's prototype measurements, a Go route's cold start dropped from 223 ms to 116 ms and each request used 40% less CPU. The prime-counting Rust route got slower, serving 12–19% fewer requests per second, because V8 optimizes that tight loop better than wasmtime's compiler.
It's opt-in because its output runs only on the operating system and CPU architecture it was built for, so a build made on a Mac won't run on a Linux server, and the deploy more than doubles in size. Polyroute's README has the setup, the full measurements, and the trade-offs.
Measured, not claimed
The honest headline is narrower than "Rust is fast."
Rust helps routes that compute. It doesn't help routes that wait. A database query or a model call takes as long from Rust as it does from TypeScript, and every call into WebAssembly has a fixed cost.
Here's the same prime-counting algorithm in Rust and in TypeScript, from Polyroute's local Farm.js benchmark on an Apple M1. Each figure is the median of ten rounds:
| Route | Connections | TypeScript p95 | Rust p95 |
|---|---|---|---|
| Primes below 100,000 | 1 | 6.22 ms | 3.32 ms |
| Primes below 100,000 | 10 | 57.92 ms | 35.00 ms |
| Primes below 2 | 10 | 3.08 ms | 4.06 ms |
On the heavy request, Rust cut p95 latency by 40–47%. At 10 connections it roughly doubled throughput, from 188 to 399 requests per second. On the light one, Rust was slower: there's almost no work to speed up, so the fixed cost dominates. A second, identical TypeScript server in that run varied by 17% on the light case, so treat small differences there as noise. Method and full results
I also ran it hosted. One Vercel preview in iad1 served the Rust route, its TypeScript twin, and an identical TypeScript copy as a noise control. I sent 3,030 requests from my laptop through Vercel's San Francisco edge: five interleaved rounds of 180 measured requests per route at 10 connections, with every response checked byte for byte.
| Route | p50 | p95 |
|---|---|---|
| Rust | 100.3 ms | 118.6 ms |
| TypeScript | 105.4 ms | 122.7 ms |
| TypeScript, control copy | 104.5 ms | 123.5 ms |
Rust won the median in all five rounds, by about 5 ms. The p95 difference was too small to call. Most of each request was the trip itself: a near-empty request took about 97 ms. Rust shrank the compute, which is the small part of that request. Put a heavier computation behind the route, or a caller inside the same region, and the compute becomes a larger share of what you wait for.
Go is a reuse story today, not a speed one. Polyroute measured a Go route that does almost no work at about four times the per-request cost of TypeScript. Bring Go code you already have and trust; don't port a fast TypeScript route to Go hoping it gets faster.
So measure your own endpoint. Rust is worth trying on a route that spends most of its time computing. Leave a route that mostly waits in TypeScript.
Limits of the beta
Two things to know before you try it:
- Tested on the Node server. We test
farm build --preset node-serverwith Polyroute's default V8 runtime. The Rust route also ran on a Vercel preview for the numbers above, but other deploy targets aren't verified yet. - Light routes cost more. A near-empty Rust route costs about 1.8 times a TypeScript one per request, and Go about 4 times. Keep routes that do little work in TypeScript.
The API routes guide has the setup and the tested versions. Polyroute's README covers the languages, limits, and runtime options.
If you have Rust or Go code you'd rather call than rewrite, try it. Then tell me where it breaks: open an issue on Farm.js or on Polyroute.
Thanks for building with us.