Typst Webservice exposes a small Axum-based HTTP API that compiles Typst templates into PDFs given a JSON input. Templates, assets, and fonts are preloaded from an on-disk directory.
GET /render-pdf/{template}/{file_name}renders a single template into PDF.POST /render-pdf/batchrenders multiple templates and returns a streaming ZIP archive.- Streaming ZIP writer keeps memory usage predictable for large batches.
- Detailed error responses include unique reference IDs for troubleshooting.
- Structured logging powered by
tracing.
cargo runBy default the server loads templates from the assets/ directory in the project root and binds to 127.0.0.1:8080.
You can point the service at a different assets directory using either a command-line argument or an environment variable:
# Command-line override
cargo run -- ./my-templates
# Environment variable override
TWS_DIR=./my-templates cargo runThe command-line argument takes precedence; both fall back to assets/ when unset.
cargo testIntegration tests exercise both single and batch rendering flows using fixtures from the assets/ directory.