Files
WRNexusJS/examples/basic-app/app/api/echo.ts
Clintchiz 586a6db8ff
Quality / quality (ubuntu-latest) (push) Failing after 21s
Quality / quality (windows-latest) (push) Canceled after 0s
release: WRNexusJS 0.8.0
2026-08-02 23:18:51 +05:30

19 lines
638 B
TypeScript

import type { Context } from "@wrnexus/core";
// Demonstrates method-specific handlers on a single route file.
// GET /api/echo -> usage hint
// POST /api/echo -> echoes the JSON body back
export const GET = async () => {
return Response.json({ usage: "POST JSON here and it will be echoed back" });
};
export const POST = async (ctx: Context) => {
const body = await ctx.req.json().catch(() => undefined);
if (body === undefined)
return Response.json(
{ error: "Request body must be valid JSON." },
{ status: 400, headers: { "cache-control": "no-store" } },
);
return Response.json({ received: body });
};