# @hono-dev/zod-body-validator

> Zod Json/Form Validator Middleware

Latest version **0.1.1** (published 2023-12-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @hono-dev/zod-body-validator
pnpm add @hono-dev/zod-body-validator
yarn add @hono-dev/zod-body-validator
bun add @hono-dev/zod-body-validator
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-12-30 |
| First published | 2023-12-24 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Willin Wang |
| Maintainers | willin |
| Keywords | hono, zod, validator, body, json, form |

## Links

- npm: https://www.npmjs.com/package/@hono-dev/zod-body-validator
- Repository: https://github.com/willin/api
- Homepage: https://github.com/willin/api#readme
- Issues: https://github.com/willin/api/issues
- npm.io page: https://npm.io/package/@hono-dev/zod-body-validator

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.1 (latest) — 2023-12-30
- 0.1.0 — 2023-12-24
- 0.0.1 — 2023-12-24

## README

# Zod body validator middleware for Hono

The validator middleware using [Zod](https://zod.dev) for [Hono](https://honojs.dev) applications.
You can write a schema with Zod and validate the incoming values.

For more details: <https://github.com/willin/api>

## Usage

```ts
import { z } from 'zod';
import { zBodyValidator } from '@hono-dev/zod-body-validator';

const schema = z.object({
  name: z.string(),
  age: z.number()
});

app.post('/author', zBodyValidator(schema), (c) => {
  const data = c.req.valid('form');
  return c.json({
    success: true,
    message: `${data.name} is ${data.age}`
  });
});
```

Hook:

```ts
app.post(
  '/post',
  zBodyValidator(schema, (result, c) => {
    if (!result.success) {
      return c.text('Invalid!', 400);
    }
  })
  //...
);
```

## 赞助 Sponsor

维护者 Owner： [Willin Wang](https://willin.wang)

如果您对本项目感兴趣，可以通过以下方式支持我：

- 关注我的 Github 账号：[@willin](https://github.com/willin) [![github](https://img.shields.io/github/followers/willin.svg?style=social&label=Followers)](https://github.com/willin)
- 参与 [爱发电](https://afdian.net/@willin) 计划
- 支付宝或微信[扫码打赏](https://user-images.githubusercontent.com/1890238/89126156-0f3eeb80-d516-11ea-9046-5a3a5d59b86b.png)

Donation ways:

- Github: <https://github.com/sponsors/willin>
- Paypal: <https://paypal.me/willinwang>
- Alipay or Wechat Pay: [QRCode](https://user-images.githubusercontent.com/1890238/89126156-0f3eeb80-d516-11ea-9046-5a3a5d59b86b.png)

## 许可证 License

Apache 2.0

This software uses:

- [@hono/zod-validator](https://github.com/honojs/middleware/tree/main/packages/zod-validator)

---
_Source: https://npm.io/package/@hono-dev/zod-body-validator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
