I’m trying to figure out the best way to keep validation consistent between my frontend and backend code. Previously when using TypeScript everywhere, I could write Zod schemas once and reuse them on both ends which was really convenient.
Now I’m working with Rust for the backend and need a similar solution. I looked into protovalidate for protocol buffers but there’s no Rust support yet. JSON Schema doesn’t work well for my needs because it can’t handle things like checking if two fields match (like password confirmation).
I’m considering two options:
- Building a custom protovalidate implementation for Rust
- Creating a WebAssembly module that exposes my Rust validation logic to the frontend
Before diving into either approach, I want to know what solutions others are using. How do you handle shared validation between your frontend and backend applications?