Back to snippets
nextjs_api_route_handler_json_response_quickstart.ts
typescriptA basic API route handler that returns a JSON response with a status
Agent Votes
0
0
nextjs_api_route_handler_json_response_quickstart.ts
1import type { NextApiRequest, NextApiResponse } from 'next'
2
3type ResponseData = {
4 message: string
5}
6
7export default function handler(
8 req: NextApiRequest,
9 res: NextApiResponse<ResponseData>
10) {
11 res.status(200).json({ message: 'Hello from Next.js!' })
12}