Templates API
Endpoints for managing Typst template files.
List Templates
GET /api/templates
Returns all templates with their metadata. If a query parameter is provided, filters by search term.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
q | string | Search query (optional) |
Example
bash
curl http://localhost:3000/api/templatesResponse
json
[
{
"name": "universal-template",
"type": "file",
"title": "Universal Report",
"description": "A general-purpose report template",
"exampleData": { "title": "Report", "body": "Content" }
},
{
"name": "student",
"type": "folder"
}
]Get Template
GET /api/templates/:name
Get a template'''s Typst content and metadata.
Path Parameters
| Parameter | Description |
|---|---|
name | Template name (supports subfolder paths like student/student-card) |
Example
bash
curl http://localhost:3000/api/templates/student/student-cardResponse
json
{
"content": "#let data = json.decode(sys.inputs.at(\"data\"))...",
"title": "Student Card",
"description": "Compact student information card",
"exampleData": { "name": "Alice Johnson" }
}Create / Update Template
PUT or POST /api/templates/:name
Create a new template or update an existing one.
Path Parameters
| Parameter | Description |
|---|---|
name | Template name (supports subfolder paths) |
Request Body
json
{
"content": "#let data = json.decode(sys.inputs.at(\"data\"))\n= #data.title",
"title": "My Report",
"description": "A sample report template",
"exampleData": {
"title": "Hello",
"body": "World"
}
}| Field | Type | Required | Description |
|---|---|---|---|
content | string | Yes | Typst template content (max 1,000,000 chars) |
title | string | No | Display title for the template metadata |
description | string | No | Description for the template metadata |
exampleData | object | No | Example JSON data for preview |
Example
bash
curl -X PUT http://localhost:3000/api/templates/my-report \
-H "Content-Type: application/json" \
-d '\''{
"content": "#let data = json.decode(sys.inputs.at(\"data\"))\n= #data.title",
"title": "My Report",
"description": "A sample report"
}'\''Delete Template
DELETE /api/templates/:name
Delete a template.
Example
bash
curl -X DELETE http://localhost:3000/api/templates/my-reportResponse
204 No Content
Folders
List Folders
GET /api/folders
List all template folder names.
Create Folder
POST /api/folders
json
{
"name": "academy"
}Delete Folder
DELETE /api/folders/:name
Delete a template folder (recursive).
bash
curl -X DELETE http://localhost:3000/api/folders/academy