Tech News
← Back to articles

Rust and WASM for Form Validation

read original related products more articles

In recent years, Rust and WebAssembly have become much more usable for pure backend-style engineers. When I say “pure backend-style”, I mean people who never wrapped their heads around React, SPAs, and all that stuff. This, unsurprisingly, includes me.

For a very long time, in order to use WASM you were strongly guided towards using Webpack and a whole array of Node-related tools in order to just get started. These days, luckily, the story has become much more streamlined. In today’s tutorial, we’re going to create a quick project which includes both a web server in Rust which renders HTML templates, and a small WASM component (served by the same web server) that does form validation.

Why?

Well, I want to keep a reference handy about how this can be done. But I also want to hear if I’m doing something wrong or suboptimally.

As to why Rust/WASM instead of standard JS or TS? For one, I like to see how far we’ve come with WASM, and there is something very appealing about having the same code shared across the frontend and the backend, especially if it means potentially having the same data structures when serialising/deserialising data from one end to the other.

I’m using form validation as a placeholder. It shows all the crucial aspects to use WASM instead of JS, like wiring up DOM events to Rust functions, and then reacting to those events.

Stack

This post is being written in early-to-mid 2025. And the stack I currently jive with is as follows:

wasm-bindgen 0.2

wasm-pack 0.13

... continue reading