Socket
Book a DemoInstallSign in
Socket

@hono/ajv-validator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hono/ajv-validator

Validator middleware using Ajv

latest
Source
npmnpm
Version
0.0.2
Version published
Weekly downloads
12
-20%
Maintainers
1
Weekly downloads
 
Created
Source

Ajv validator middleware for Hono

codecov

Validator middleware using Ajv for Hono applications. Define your schema with Ajv and validate incoming requests.

Usage

No Hook:

import { type JSONSchemaType } from 'ajv'
import { ajvValidator } from '@hono/ajv-validator'

const schema: JSONSchemaType<{ name: string; age: number }> = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    age: { type: 'number' },
  },
  required: ['name', 'age'],
  additionalProperties: false,
} as const

const route = app.post('/user', ajvValidator('json', schema), (c) => {
  const user = c.req.valid('json')
  return c.json({ success: true, message: `${user.name} is ${user.age}` })
})

Hook:

import { type JSONSchemaType } from 'ajv'
import { ajvValidator } from '@hono/ajv-validator'

const schema: JSONSchemaType<{ name: string; age: number }> = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    age: { type: 'number' },
  },
  required: ['name', 'age'],
  additionalProperties: false,
}

app.post(
  '/user',
  ajvValidator('json', schema, (result, c) => {
    if (!result.success) {
      return c.text('Invalid!', 400)
    }
  })
  //...
)

Author

Illia Khvost https://github.com/ikhvost

License

MIT

FAQs

Package last updated on 17 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts