Next.js Response Formatting
📖 Scenario: You are building a simple Next.js API route that returns user data in a formatted JSON response. This is common when creating backend endpoints for web apps.
🎯 Goal: Create a Next.js API route that returns a JSON response with a status field and a data field containing user information.
📋 What You'll Learn
Create a Next.js API route handler function named
handlerDefine a user object with exact fields:
id, name, and emailCreate a response object with
status set to success and data containing the user objectReturn the response using Next.js
res.status(200).json() method💡 Why This Matters
🌍 Real World
API routes in Next.js are used to build backend endpoints that send JSON data to frontend apps or other services.
💼 Career
Understanding how to format and send JSON responses in Next.js API routes is essential for full-stack web development roles.
Progress0 / 4 steps