Nitro · NITRO0005

Use readValidatedBody for validated request bodies

When a Nitro handler validates a request body, read and validate it through the H3 utility.
NITRO0005vite-doctor/nitrorequestwarnSuggestion

Run this rule

pnpm vite-doctor . --framework nitro --rules nitro/request/prefer-validated-body

Why it matters

Raw request input and validation can drift apart when they are separate operations. Nitro and h3 provide validated helpers that keep parsing and validation coupled at the request boundary.

Use readValidatedBody(event, validator) instead of readBody(event) followed by separate validation.

Example

Keep reading and validation together

Before

export default defineEventHandler(async (event) => {
  const input = await readBody(event)
  const value = validator.parse(input)

  return value
})

After

export default defineEventHandler(async (event) => {
  const value = await readValidatedBody(event, validator)

  return value
})
Copyright © 2026