Skip to content

Report ​

POST /api/report

Compile a saved template by name with JSON data and return a PDF.

Request Body ​

json
{
  "template": "student/student-card",
  "data": {
    "name": "John Doe",
    "grade": "A",
    "course": "Mathematics"
  }
}
FieldTypeRequiredDescription
templatestringYesTemplate name (including subfolder path)
dataobjectYesJSON data to inject as Typst variables
variableNamestringNoCustom variable name (default: data)

Example ​

bash
curl -X POST http://localhost:3000/api/report \
  -H "Content-Type: application/json" \
  -d '\''{
    "template": "student/student-card",
    "data": {
      "name": "John Doe",
      "grade": "A",
      "course": "Mathematics"
    }
  }'\'' \
  -o report.pdf

Response ​

Returns application/pdf with the compiled PDF content.

A X-Template-Name header is included with the template name used.

Error Codes ​

CodeDescription
400Missing or invalid template or data fields
404Template not found
413Payload too large
429Rate limit exceeded for compilation
500Typst compilation error or template not found

Caching ​

Compiled PDFs are cached using an LRU cache (configurable via REPORTS_CACHE_SIZE, default 100). Subsequent requests with the same template and data return cached results.

Design and Dev by David Lam