TypstAPI: send it your typst files and attachments, it returns your PDF file
1.0K
A simple web API that processes Typst documents and returns PDFs. The API accepts file uploads and JSON data, processes them using the Typst CLI, and returns a PDF (with optional gzip compression). It also supports merging additional PDFs before and after the Typst-generated PDF.
Check out the example directory for a complete working example of how to use this API, including:
main.typ)splash192.png)For local development:
For Docker deployment:
git clone <repository-url>
cd typstapi
go build
docker build -t typstapi .
# Set custom port (optional, defaults to 8080)
export PORT=3000
# Run the server
./typstapi
# Run with default port 8080
docker run -p 8080:8080 typstapi
# Run with custom port
docker run -e PORT=3000 -p 3000:3000 typstapi
See the Docker Hub page sslboard/typstapi for more details.
# Pull the image
docker pull sslboard/typstapi:v1.0.0
# Run the container
docker run -p 8080:8080 sslboard/typstapi:v1.0.0
Process a Typst document and return the compiled PDF. Optionally merge additional PDFs before and after the Typst-generated PDF.
Request:
:filename - The name of the main Typst file to processForm Fields:
data: (Optional) JSON string that will be saved as data.json in the processing directorypre_ and ending with .pdf will be merged before the Typst outputpost_ and ending with .pdf will be merged after the Typst outputResponse:
Example using curl:
# Standard request (PDF will be compressed if browser supports gzip)
curl -X POST http://localhost:8080/typst/main.typ \
-F "main.typ=@/path/to/main.typ" \
-F "logo.jpeg=@/path/to/logo.jpeg" \
-F 'data={"hello": "world"}' \
--output output.pdf
# Request with pre and post PDFs
curl -X POST http://localhost:8080/typst/main.typ \
-F "main.typ=@/path/to/main.typ" \
-F "logo.jpeg=@/path/to/logo.jpeg" \
-F 'data={"hello": "world"}' \
-F "pre_1.pdf=@/path/to/cover.pdf" \
-F "pre_2.pdf=@/path/to/toc.pdf" \
-F "post_1.pdf=@/path/to/appendix.pdf" \
--output output.pdf
# Explicitly request no compression by not sending Accept-Encoding header
curl -X POST http://localhost:8080/typst/main.typ \
-H "Accept-Encoding: identity" \
-F "main.typ=@/path/to/main.typ" \
-F "logo.jpeg=@/path/to/logo.jpeg" \
-F 'data={"hello": "world"}' \
--output output.pdf
The API supports merging additional PDFs before and after the Typst-generated PDF:
Pre-PDFs:
pre_ and ending with .pdfpre_1.pdf, pre_2.pdf, etc.Post-PDFs:
post_ and ending with .pdfpost_1.pdf, post_2.pdf, etc.The final PDF will be assembled in this order:
The API returns appropriate HTTP status codes:
When a Typst compilation error occurs, the API returns:
Created by Chris Hartwig for SSLBoard.com.
Content type
Image
Digest
sha256:9d4065481…
Size
29.8 MB
Last updated
over 1 year ago
docker pull sslboard/typstapi