route.ts. What will the client receive when making a GET request?import { NextResponse } from 'next/server'; export async function GET() { return NextResponse.json({ message: 'Hello from GET!' }); }
The GET function returns a JSON response using NextResponse.json. This sends a JSON object with the key message and value Hello from GET!.
route.ts. Which code snippet is syntactically correct?In Next.js route handlers, the function must be exported, named in uppercase (POST), and can be async. The parameter request is typed as Request. Option C follows this pattern correctly.
import { NextResponse } from 'next/server'; let count = 0; export async function PUT() { count += 1; return NextResponse.json({ count }); }
The variable count is declared outside the handler, so it persists across requests in the server environment. Each PUT request increments count by 1 and returns it in JSON.
export async function DELETE() { const data = await request.json(); return new Response('Deleted'); }
The function tries to use request but it is not passed as a parameter. Route handlers must declare request as a parameter to access the request body.
route.ts files.Route handlers in Next.js run on the server, so they can safely access environment variables. They can export multiple HTTP method functions per file. They do not cache responses automatically, and they are functions, not components.