Next.js
Wire Restaq into a Next.js App Router catch-all route.
Next.js support ships with restaq — no separate package. If you've already run pnpm add restaq, you have toNextJsHandler, which converts your Relay instance into a standard App Router route handler.
Setup
Create a catch-all route to receive webhooks from all your plugins:
// app/api/webhook/[...all]/route.ts
import { toNextJsHandler } from 'restaq/next-js';
import { restaq } from '@/relay';
export const { POST } = toNextJsHandler(restaq);This one route serves every plugin you register, at /api/webhook/<provider> (e.g. /api/webhook/stripe).
How it works
toNextJsHandler(restaq) returns a route handler object:
const handler = toNextJsHandler(restaq);
// handler.POST is a standard Next.js route handler:
// async (req: Request, ctx: { params: Promise<{ all: string[] }> }) => ResponseOn each request it awaits ctx.params (required for dynamic routes since Next.js 16), pulls the provider segment out of it (e.g. "stripe" from /api/webhook/stripe), and delegates to restaq.handler(req, { params: { all } }).
It's built entirely on web-standard Request/Response — no import from 'next' anywhere — so the same code runs in any Node.js runtime, not just Next.js.
Management endpoints
Beyond webhook ingestion, you'll likely want endpoints to list, inspect, retry, and replay executions:
// app/api/executions/route.ts — List executions
import { restaq } from '@/relay';
export async function GET() {
const executions = await restaq.listExecutions();
return Response.json(executions);
}// app/api/executions/[id]/route.ts — Inspect one execution
import { restaq } from '@/relay';
export async function GET(_req: Request, ctx: { params: Promise<{ id: string }> }) {
const { id } = await ctx.params;
const execution = await restaq.listExecutions().then((e) => e.find((x) => x.id === id));
const steps = await restaq.listSteps(id);
const logs = await restaq.listLogs(id);
return Response.json({ execution, steps, logs });
}// app/api/executions/[id]/retry/route.ts — Retry an execution
import { restaq } from '@/relay';
export async function POST(_req: Request, ctx: { params: Promise<{ id: string }> }) {
const { id } = await ctx.params;
const execution = await restaq.retryExecution(id);
return Response.json(execution);
}// app/api/executions/[id]/replay/route.ts — Replay an execution
import { restaq } from '@/relay';
export async function POST(_req: Request, ctx: { params: Promise<{ id: string }> }) {
const { id } = await ctx.params;
const execution = await restaq.replayExecution(id);
return Response.json(execution);
}These give you HTTP access to the full Relay API. Build a dashboard on top of them, or call them from your CLI or internal tools.