An open API service indexing awesome lists of open source software.

https://github.com/vasisouv/painter

A Typescript Node.js REST API service for rendering emails and pdfs.
https://github.com/vasisouv/painter

email eta express mjml pdf puppeteer renderer

Last synced: 4 days ago
JSON representation

A Typescript Node.js REST API service for rendering emails and pdfs.

Awesome Lists containing this project

README

          

# Painter 🎨

A Typescript Node.js REST API service for rendering emails and pdfs.

Features:
* **[Express](https://expressjs.com/)** - app web framework
* **[Eta](https://eta.js.org/)** - template composition
* **[mjml](https://mjml.io/)** - responsive email framework
* **[playwright](https://playwright.dev/)** - html to pdf rendering

## How It Works

Painter is a REST API with dynamic endpoints, representing filesystem template files, with
each path pointing to specific template file. There are two base api paths:

### Emails

Base path:`/api/paint/email/:templatePath`

Emails use the mjml framework and markup language to ensure mail client compatibility.

Example:

```
curl --request POST \
--url http://localhost:3003/api/paint/email/example \
--header 'Content-Type: application/json' \
--data '{
"items": [
{
"description": "Alcohol free beer",
"price": "15.00",
"quantity": 2
},
{
"description": "Coffee",
"price": "10.00",
"quantity": 4
},
{
"description": "Potato chips",
"price": "4.00",
"quantity": 5
}
]
}
'
```

The service responds with the email's HTML, ready to be sent.
```









#outlook a { padding:0; }
body { margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%; }
table, td { border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt; }
img { border:0;height:auto;line-height:100%; outline:none;text-decoration:none;-ms-interpolation-mode:bicubic; }
p { display:block;margin:13px 0; }

....
```

### Pdfs

Base path:`/api/paint/pdf/:templatePath`

Pdfs are rendered from HTML using Playwright.

Example:

```
curl --request POST \
--url http://localhost:3003/api/paint/pdf/example \
--header 'Content-Type: application/json' \
--data '{
"items": [
{
"description": "Alcohol free beer",
"price": "15.00",
"quantity": 2
},
{
"description": "Coffee",
"price": "10.00",
"quantity": 4
},
{
"description": "Potato chips",
"price": "4.00",
"quantity": 5
}
]
}
'
```

The service responds with the pdf Buffer Blob.