// app/api/hello/route.js
export async function GET() { return Response.json({ message: "Hello from Next.js 15 API Route" });
}
// app/api/hello/route.js
export async function GET() { return Response.json({ message: "Hello from Next.js 15 API Route" });
}
// app/api/hello/route.js
export async function GET() { return Response.json({ message: "Hello from Next.js 15 API Route" });
}
// app/api/users/route.js
export async function POST(request) { try { const body = await request.json(); return Response.json( { id: Date.now(), ...body }, { status: 201 } ); } catch (error) { return Response.json( { error: "Invalid JSON body" }, { status: 400 } ); }
}
// app/api/users/route.js
export async function POST(request) { try { const body = await request.json(); return Response.json( { id: Date.now(), ...body }, { status: 201 } ); } catch (error) { return Response.json( { error: "Invalid JSON body" }, { status: 400 } ); }
}
// app/api/users/route.js
export async function POST(request) { try { const body = await request.json(); return Response.json( { id: Date.now(), ...body }, { status: 201 } ); } catch (error) { return Response.json( { error: "Invalid JSON body" }, { status: 400 } ); }
}
// app/api/hello/route.js (updated)
export async function GET(request) { const authHeader = request.headers.get("Authorization"); if (authHeader !== "Bearer nextjs15-test-token") { return Response.json( { error: "Unauthorized" }, { status: 401 } ); } return Response.json({ message: "Hello Authenticated User" });
}
// app/api/hello/route.js (updated)
export async function GET(request) { const authHeader = request.headers.get("Authorization"); if (authHeader !== "Bearer nextjs15-test-token") { return Response.json( { error: "Unauthorized" }, { status: 401 } ); } return Response.json({ message: "Hello Authenticated User" });
}
// app/api/hello/route.js (updated)
export async function GET(request) { const authHeader = request.headers.get("Authorization"); if (authHeader !== "Bearer nextjs15-test-token") { return Response.json( { error: "Unauthorized" }, { status: 401 } ); } return Response.json({ message: "Hello Authenticated User" });
} - Node.js 18.17 or later installed (required for Next.js 15)
- Existing Next.js 15 project (or create one with npx create-next-app@latest)
- Insomnia 5.0 downloaded from the official site
- Basic understanding of REST API concepts and Next.js App Router - Click Create a Workspace
- Name the workspace "Next.js 15 API Testing" (or a name of your choice)
- Select "Blank" as the workspace template, then click Create - Navigate to your Next.js project directory
- Create the folder structure app/api/hello
- Add a route.js file with the following code: - In your Insomnia workspace, click the + button next to "Requests" and select New Request
- Name the request "GET /api/hello"
- Set the HTTP method to GET
- Enter the URL: http://localhost:3000/api/hello - Click the Environment button (gear icon) in the top right of the Insomnia window
- Select Manage Environments
- Add a new environment variable: base_url with value http://localhost:3000
- Save the environment, then close the modal
- Update your GET request URL to use the variable: {{base_url}}/api/hello - Create the folder structure app/api/users in your Next.js project
- Add a route.js file with the following code: - New Request → Name: "POST /api/users", Method: POST
- URL: {{base_url}}/api/users
- Go to the Body tab, select JSON as the body type
- Enter the following JSON: {"name": "Test User", "email": "[email protected]"} - Open your "GET /api/hello" request
- Go to the Headers tab
- Add a new header: Key: Authorization, Value: Bearer nextjs15-test-token
- Click Send — you should see the authenticated response
- Remove the header and send again to confirm you get a 401 Unauthorized error - Check the Next.js terminal output for server-side errors if requests fail
- Use Insomnia’s Timeline tab to view full request/response details, including headers and timing
- Export your Insomnia workspace as a JSON file to share with your team (Workspace → Export)
- Use Insomnia’s Code Generation feature (right-click request → Generate Code) to get fetch or Axios snippets for your frontend
- Test edge cases like invalid JSON bodies, missing headers, and 404 routes to ensure your API handles errors properly - Next.js 15 Route Handlers Docs
- Insomnia 5.0 Documentation