/Wiki/sources/honojs__hono/2026/https-hono-dev-llms-full-txt-manual-validator-78b974053630-manual-validator-s0101-c0000.md
Manual validator (1) - hono-docs
Manual validator (1) Source evidence: /Sources/raw/honojs hono/honojs hono.md Canonical citation: https://hono.dev/llms full.txt manual validator Summary Fir...
Manual validator (1)
Source evidence: /Sources/raw/honojshono/honojshono.md Canonical citation: https://hono.dev/llms-full.txt#manual-validator
Summary
First, introduce a way to validate incoming values without using the third-party Validator. Import validator from hono/validator. ts import { validator } from 'hono/validator' To validate form data, specify form as the first...
Content
First, introduce a way to validate incoming values without using the third-party Validator.
Import validator from hono/validator.
import { validator } from 'hono/validator'To validate form data, specify form as the first argument and a callback as the second argument.
In the callback, validates the value and return the validated values at the end.
The validator can be used as middleware.
app.post(
'/posts',
validator('form', (value, c) => {
const body = value['body']
if (!body || typeof body !== 'string') {
return c.text('Invalid!', 400)
}
return {
body: body,
}
}),
//...Within the handler, you can get the validated value with c.req.valid('form').
, (c) => {
const { body } = c.req.valid('form')
// ... do something
return c.json(
{
message: 'Created!',
},
201
)
}