Skip to content

yelixjs/js-hono-zod-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zValidator Abstractor

The zValidator abstractor is a utility for validating HTTP requests using Zod schemas in conjunction with the Hono framework. It simplifies request validation by providing a middleware that integrates seamlessly with Yelix's Hono-based abstractions.

Features

  • Validate request data from various sources (json, query, header, etc.).
  • Leverages the power of Zod schemas for type-safe validation.
  • Easily integrates with Yelix's Hono middleware ecosystem.

Installation

To use the zValidator abstractor:

deno add jsr:@yelix/zod-validator

Usage

Here's an example of how to use the zValidator abstractor in your Hono application:

import { z } from 'zod';
import { zValidatorYelix } from '@yelix/zod-validator';

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

const validateMiddleware = zValidatorYelix('json', schema);

// Use the middleware in your Hono route
app.post('/user', validateMiddleware, (c) => {
  const data = c.req.validatedData;
  return c.json({ message: 'Validation successful', data });
});

License

This project is licensed under the MIT License.

About

Abstractor of zValidator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published