Skip to main content
Home

Built and signed on GitHub Actions

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

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
94%
Published
6 days ago (1.0.0)

TypeBox validator middleware for Hono

codecov

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

Usage

No Hook:

import { tbValidator } from '@hono/typebox-validator'
import Type from 'typebox'

const User = Type.Object({
  name: Type.String(),
  age: Type.Number(),
})

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

Hook:

import { tbValidator } from '@hono/typebox-validator'
import Type from 'typebox'

const User = Type.Object({
  name: Type.String(),
  age: Type.Number(),
})

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

Author

Curtis Larson https://github.com/curtislarson

License

MIT

Built and signed on
GitHub Actions

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@hono/typebox-validator

Import symbol

import * as typebox_validator from "@hono/typebox-validator";
or

Import directly with a jsr specifier

import * as typebox_validator from "jsr:@hono/typebox-validator";

Add Package

pnpm i jsr:@hono/typebox-validator
or (using pnpm 10.8 or older)
pnpm dlx jsr add @hono/typebox-validator

Import symbol

import * as typebox_validator from "@hono/typebox-validator";

Add Package

yarn add jsr:@hono/typebox-validator
or (using Yarn 4.8 or older)
yarn dlx jsr add @hono/typebox-validator

Import symbol

import * as typebox_validator from "@hono/typebox-validator";

Add Package

vlt install jsr:@hono/typebox-validator

Import symbol

import * as typebox_validator from "@hono/typebox-validator";

Add Package

npx jsr add @hono/typebox-validator

Import symbol

import * as typebox_validator from "@hono/typebox-validator";

Add Package

bunx jsr add @hono/typebox-validator

Import symbol

import * as typebox_validator from "@hono/typebox-validator";