Skip to content

Templates API

Endpoints for managing Typst template files.

List Templates

GET /api/templates

Returns all templates. If a query parameter is provided, filters by search term.

Query Parameters

ParameterTypeDescription
qstringSearch query (optional)

Example

bash
curl http://localhost:3000/api/templates

Response

json
[
  {
    "name": "universal-template",
    "type": "file",
    "title": "Universal Report",
    "description": "A general-purpose report template",
    "exampleData": { "title": "Report", "body": "Content" }
  },
  {
    "name": "student",
    "type": "folder"
  }
]

Create Folder

POST /api/folders

Create a new template folder.

Request Body

json
{
  "name": "academy"
}
FieldTypeRequiredDescription
namestringYesFolder name

Get Template

GET /api/templates/:name

Get a template's Typst content.

Path Parameters

ParameterDescription
nameTemplate name (supports subfolder paths like student/student-card)

Example

bash
curl http://localhost:3000/api/templates/student/student-card

Response

Returns text/typst with the raw template content.


Create / Update Template

PUT /api/templates/:name

Create a new template or update an existing one.

Path Parameters

ParameterDescription
nameTemplate name (supports subfolder paths)

Request

Send raw Typst content as the body with Content-Type: text/typst.

Example

bash
curl -X PUT http://localhost:3000/api/templates/my-report \
  -H "Content-Type: text/typst" \
  -d '#let data = json.decode(sys.inputs.at("data"))
= #data.title

#data.body'

Optionally send JSON metadata:

bash
curl -X PUT "http://localhost:3000/api/templates/my-report?meta=1" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "My Report",
    "description": "A sample report",
    "exampleData": { "title": "Hello" }
  }'

Delete Template

DELETE /api/templates/:name

Delete a template.

Example

bash
curl -X DELETE http://localhost:3000/api/templates/my-report

Response

204 No Content


List Folders

GET /api/folders

List all template folders.


Delete Folder

DELETE /api/folders

Delete a template folder.

Request Body

json
{
  "name": "academy"
}

Design and Dev by David Lam