Why this matters
Integrates with RSC, cache tags, and Edge runtime.
Prefer app/api route handlers over legacy pages/api. Return NextResponse.json, validate input, and handle allowed HTTP methods explicitly.
Integrates with RSC, cache tags, and Edge runtime.
Side-by-side examples engineers can pattern-match during review.
// pages/api/create.ts (legacy)
export default (req,res)=>{ res.status(200).json({}) }import { NextResponse } from 'next/server'
export async function POST(req){ const body = await req.json(); /* validate */ return NextResponse.json({ ok:true },{ status:201 }) }
export function GET(){ return NextResponse.json({ error:'Method not allowed' },{ status:405 }) }pages/api/*app/api/* with NextResponse.json()From the same buckets as this rule.