Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP2stack specificStack: Next.js
nextjsapisimplicitybackend
Skip the method switch when an API route handles one verb
A handler that supports a single HTTP method doesn't need a switch on req.method; handle the verb directly (and reject others) to cut boilerplate.
PR: vinify-frontend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codets
| 1 | switch (method) { |
| 2 | case 'PATCH': |
| 3 | return handlePatch(); |
| 4 | default: |
| 5 | return res.status(405).end(); |
| 6 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | if (method !== 'PATCH') return res.status(405).end(); |
| 2 | return handlePatch(); |
Explanation (EN)
Objašnjenje (HR)