Validation — Basics · Hono

Check a JSON body, a path parameter and a query value before the handler runs, with Hono's validator, and answer 400 with a message that names the problem.

What you will learn

Read the theory for Validation

All Basics lessons

All Hono courses

loading types…

What you'll learn

  • Put validator('json', …) from hono/validator in front of a handler and answer 400 from inside it
  • Read the validated, typed value with c.req.valid('json') instead of parsing the body again
  • Validate a path parameter and a query value the same way, and share a validator between routes