0.1.1 • Published 4 months ago

@hono-dev/zod-body-validator v0.1.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

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:

许可证 License

Apache 2.0

This software uses:

0.1.1

4 months ago

0.1.0

4 months ago

0.0.1

4 months ago