Next.js App Router API patterns — Route Handlers, Server Actions, middleware, validation, caching, error handling
92
90%
Does it follow best practices?
Impact
95%
1.58xAverage score across 5 eval scenarios
Passed
No known issues
Build a Next.js App Router endpoint that receives webhooks from a payment provider (like Stripe). The endpoint should:
/api/webhooks/paymentspayment.completed, payment.failed, payment.refundedThe payment provider sends payloads like:
{
"event": "payment.completed",
"data": {
"paymentId": "pay_123",
"amount": 4999,
"currency": "usd",
"customerId": "cust_456"
},
"timestamp": "2024-01-15T10:30:00Z"
}The provider also sends a x-webhook-signature header for verification (simulate this -- just check the header exists).
Also add a GET endpoint at /api/webhooks/payments/events to list received events, and add middleware to protect the /api/webhooks/* routes.
Produce:
app/api/webhooks/payments/route.ts -- POST handler for receiving webhooksapp/api/webhooks/payments/events/route.ts -- GET handler for listing eventsmiddleware.ts -- middleware for the webhook routespackage.json with dependenciesYou may create additional files as needed.