Nitro · Request

NITRO0003Use assertMethod for single-method handlers

Single-method Nitro handlers should use the H3 method assertion helper instead of ad hoc method checks.

Why it happens

Manual method checks can drift from H3 response behavior. assertMethod() applies the framework's method validation and 405 handling consistently.

Fix

Use assertMethod(event, "POST") for handlers that accept one HTTP method.

Example

Use assertMethod

Before

export default defineEventHandler((event) => {
  if (getMethod(event) !== 'POST') {
    throw createError({ statusCode: 405 })
  }
})

After

export default defineEventHandler((event) => {
  assertMethod(event, 'POST')
})

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --framework nitro --rules nitro/request/prefer-assert-method
Copyright © 2026