Raw API Route
POST /api/compile is a plain Node.js Route Handler — the same one the Client
Component pattern calls. It’s a normal HTTP endpoint, so it works from curl, a
mobile app, or any other client, not just this app.
import { NextResponse } from 'next/server';import { compile } from '@nandan-varma/platex';
export const runtime = 'nodejs';
export async function POST(req: Request) { const { source } = await req.json(); const result = await compile(source, { bibliography: 'bibtex' });
return NextResponse.json({ pdf: result.pdf ? result.pdf.toString('base64') : null, errors: result.errors, warnings: result.warnings, });}Every field except source is optional — see the API reference
for the full request shape.
curl -X POST http://localhost:3000/api/compile \ -H "Content-Type: application/json" \ -d '{"source": "\\documentclass{article}\\begin{document}Hi\\end{document}"}' \ | jq -r '.pdf' | base64 -d > output.pdfSee also
Section titled “See also”- Request handlers — the drop-in handler, response codes, and JSON mode.
- Client Components — the browser UI that calls this route.
- HTTP API — the underlying service wire format.