@orveth/validation-zod
v0.1.0
Published
Official Zod adapter for validating Orveth request bodies.
Downloads
88
Maintainers
Readme
@orveth/validation-zod
Official Zod adapter for validating JSON bodies on @orveth/server. Successful parses attach ctx.valid.body.
Install
npm install @orveth/validation-zod @orveth/server zodUsage
import { z } from "zod";
import { Orveth } from "@orveth/server";
import { validateBody } from "@orveth/validation-zod";
const CreateUser = z.object({
name: z.string(),
email: z.string().email(),
});
const app = new Orveth();
app.post("/users", validateBody(CreateUser), async (ctx) => {
const body = ctx.valid.body as z.infer<typeof CreateUser>;
await ctx.json({ user: body });
});
await app.listen(3000);Failures surface as HttpError 400 with code ORVETH_VALIDATION_FAILED.
License
MIT — VLODIA
