Validation
Choose a tab to use the same library in the snippet and live demo. See the validation guide for installation.
import { Http, envelope } from "fetchzen";import { z } from "zod";
const schema = z.object({ name: z.string().trim() });const api = Http.create(`${location.origin}/api/examples/`, { cache: false, secure: false, preset: envelope,});const result = await api.get("echo", { params: { name: "Ada" }, schema });console.log(result.payload.name);Ready. No request sent.
Result
Choose Run to see the response.
Event log
No events yet.
import { Http, envelope } from "fetchzen";import * as v from "valibot";
const schema = v.object({ name: v.pipe(v.string(), v.trim()) });const api = Http.create(`${location.origin}/api/examples/`, { cache: false, secure: false, preset: envelope,});const result = await api.get("echo", { params: { name: "Ada" }, schema });console.log(result.payload.name);Ready. No request sent.
Result
Choose Run to see the response.
Event log
No events yet.
What to notice
Section titled “What to notice”Try a name with surrounding spaces: the inferred payload contains the trimmed name,
without the echo response’s extra fields. The numeric-name checkbox intentionally
requires a number instead of a string to produce ERR_SCHEMA.
The demo calls this site’s bounded echo endpoint; use your own base URL in an application.
Next: transforms or safe errors.