What is Astro's server-side rendering and API endpoints?
Answer
When Astro is configured with output: "server" (or "hybrid"), it supports SSR and API routes. SSR pages: access request context: const { cookies, request, redirect, url } = Astro. Check auth: const user = await getUser(cookies.get("session")?.value); if (!user) return redirect("/login");. API routes: create src/pages/api/users.ts: export async function GET({ request }) { const users = await db.getUsers(); return new Response(JSON.stringify(users), { headers: { "Content-Type": "application/json" } }); }. Use Astro's helpers: import { APIRoute } from 'astro'. All HTTP methods (GET, POST, PUT, DELETE, PATCH) are supported. Access form data: const data = await request.formData();. Astro uses native Web Request/Response APIs — the same standard used in Cloudflare Workers, Deno, and modern runtimes. This makes Astro API routes portable across deployment targets.
Previous
What is the difference between Remix and Next.js?
Next
What is progressive enhancement in Remix?