Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
latest
nhttp/nhttpzod-validator for nhttp.
This package works with Cloudflare Workers, Node.js, Deno, BunIt is unknown whether this package works with Browsers
JSR Score
100%
Published
4 months ago (2.0.2)
## Lib zod-validator > this libs for [@nhttp/nhttp](https://jsr.io/@nhttp/nhttp) ## Usage ```ts import nhttp from "@nhttp/nhttp"; import validate, { z } from "@nhttp/zod"; const User = z.object({ username: z.string(), password: z.string(), user_info: z.object({ name: z.string(), address: z.string(), }), }); const app = nhttp(); // validate support all content-type (json, multipart, raw, urlencoded) app.post("/", validate(User), (rev) => { return rev.body.user_info; }); const userId = z.object({ userId: z.number(), }); // validate path params app.get("/users/:userId", validate(userId, "params"), (rev) => { return rev.params; }); const category = z.object({ category: z.string(), }); // validate query params app.get("/posts/:postId", validate(category, "query"), (rev) => { return rev.query; }); app.listen(8000, (_err, info) => { console.log(`Running on port ${info.port}`); }); ```