import type { APIRoute } from 'astro'; export const GET: APIRoute = async ({ request }) => { const url = new URL(request.url); const name = url.searchParams.get('name') || 'World'; return new Response( JSON.stringify({ message: `Hello, ${name}!`, timestamp: new Date().toISOString(), method: 'GET' }), { status: 200, headers: { 'Content-Type': 'application/json', }, } ); }; export const POST: APIRoute = async ({ request }) => { try { const body = await request.json(); return new Response( JSON.stringify({ message: 'Data received successfully', received: body, timestamp: new Date().toISOString(), method: 'POST' }), { status: 200, headers: { 'Content-Type': 'application/json', }, } ); } catch (error) { return new Response( JSON.stringify({ error: 'Invalid JSON', timestamp: new Date().toISOString() }), { status: 400, headers: { 'Content-Type': 'application/json', }, } ); } };