Skip to main content

@nhttp/zod@2.0.2
Built and signed on GitHub Actions

zod-validator for nhttp.

This package works with Cloudflare Workers, Node.js, Deno, BunIt is unknown whether this package works with Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
It 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

Usage

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}`);
});
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@nhttp/zod

Import symbol

import * as mod from "@nhttp/zod";

---- OR ----

Import directly with a jsr specifier

import * as mod from "jsr:@nhttp/zod";

Add Package

npx jsr add @nhttp/zod

Import symbol

import * as mod from "@nhttp/zod";

Add Package

yarn dlx jsr add @nhttp/zod

Import symbol

import * as mod from "@nhttp/zod";

Add Package

pnpm dlx jsr add @nhttp/zod

Import symbol

import * as mod from "@nhttp/zod";

Add Package

bunx jsr add @nhttp/zod

Import symbol

import * as mod from "@nhttp/zod";