Rod

Quick Start

Your first validation with Rod.

Quick Start

Rod provides a nearly identical API across all languages. Here is how to validate a simple User object.

use rod_rs::{rod_obj, string, number, RodValidator};
use serde_json::json;

fn main() {
    let schema = rod_obj! {
        name: string().min(3),
        age: number().int().min(18.0)
    };

    let data = json!({ "name": "Rod", "age": 25 });
    let input = rod_rs::io::json::wrap(&data);

    match schema.validate(&input) {
        Ok(_) => println!("Valid!"),
        Err(e) => println!("Invalid: {:?}", e.issues),
    }
}
import { rod } from 'rod-js';

async function run() {
    await rod.init(); // Initialize WASM engine

    const schema = rod.object({
        name: rod.string().min(3),
        age: rod.number().int().min(18)
    });

    const data = { name: "Rod", age: 25 };
    
    try {
        const result = schema.parse(data);
        console.log("Valid:", result);
    } catch (e) {
        console.error("Invalid:", e.message);
    }
}
import rod

schema = rod.object({
    "name": rod.string().min(3),
    "age": rod.number().int().min(18)
})

data = {"name": "Rod", "age": 25}

try:
    result = schema.parse(data)
    print("Valid:", result)
except ValueError as e:
    print("Invalid:", e)

Core Concepts

  1. The Core: All validation logic happens in a pre-compiled Rust binary.
  2. The Adapter: Rod uses a "Zero-Copy" adapter system to read your language's native objects (JS objects, Python dicts) without converting them to JSON first.
  3. Consistency: Because it's the same binary, a regex or email check will never behave differently between your React frontend and your Python API.

On this page