@hono-dev/zod-body-validator
v0.1.1
Published
Zod Json/Form Validator Middleware
Downloads
60
Readme
Zod body validator middleware for Hono
The validator middleware using Zod for Hono applications. You can write a schema with Zod and validate the incoming values.
For more details: https://github.com/willin/api
Usage
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:
app.post(
'/post',
zBodyValidator(schema, (result, c) => {
if (!result.success) {
return c.text('Invalid!', 400);
}
})
//...
);
赞助 Sponsor
维护者 Owner: Willin Wang
如果您对本项目感兴趣,可以通过以下方式支持我:
Donation ways:
- Github: https://github.com/sponsors/willin
- Paypal: https://paypal.me/willinwang
- Alipay or Wechat Pay: QRCode
许可证 License
Apache 2.0
This software uses: