Skip to content

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.

app/api/compile/route.ts
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.

Terminal window
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.pdf