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"
}
}| Field | Type | Required | Description |
|---|---|---|---|
template | string | Yes | Template name (including subfolder path) |
data | object | Yes | JSON data to inject as Typst variables |
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.pdfResponse
Returns application/pdf with the compiled PDF content.
A X-Template-Name header is included with the template name used.
Error Codes
| Code | Description |
|---|---|
400 | Missing or invalid template or data fields |
404 | Template not found |
413 | Payload too large |
429 | Rate limit exceeded for compilation |
500 | Typst compilation error or template not found |
Caching
Compiled PDFs are cached using an LRU cache (configurable size, default 100). Subsequent requests with the same template and data return cached results.