Transforms

Choose a tab to transform the response with 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() }).transform(({ name }) => ({
greeting: `Hello, ${name}`,
characters: name.length,
}));
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.greeting, result.payload.characters);
Try this requestTransform a response
Request parameters

Only Run sends a request to this site's demo API. Use synthetic data only; do not send secrets or personal files. Uploads are counted, not stored.

Ready. No request sent.

Result

Choose Run to see the response.
Event log
No events yet.

Try surrounding spaces: both the greeting and character count use the trimmed name. The inferred payload is { greeting: string; characters: number }, not { name: string }. This site’s bounded echo endpoint supplies the input; the schema transforms it locally.

Next: validation or JSON.