https://github.com/maurerkrisztian/template-api-tm
https://github.com/maurerkrisztian/template-api-tm
api emailtemplate helper microservice template
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/maurerkrisztian/template-api-tm
- Owner: MaurerKrisztian
- Created: 2022-05-11T15:24:41.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-21T20:48:09.000Z (about 4 years ago)
- Last Synced: 2025-01-12T18:52:08.680Z (over 1 year ago)
- Topics: api, emailtemplate, helper, microservice, template
- Language: Handlebars
- Homepage:
- Size: 807 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tempalte-api-tm
Template microservice. Generate html (email compatible) and pdf from the given template and data.
### Features:
- fill html templates with data
- convert html css to inline css for emails
- pdf creation form template with data (get buffer / stream)
- Send email with template.
### Add template:
1. In /src/templates/template create a new forlder with {templateName}
2. Add a {templateName}.handlebars file (template)
1. Your html \ will be replaced with inline css because this is the only way it will work with emails
3. Add a Validator class to {templateName} folder (extend TemplateValidatorAbstract<YourTemplateData> - implement the validate(data: YourTemplateData) and exampleData(): YourTemplateData)
4. Add the validator to TemplateFactory validators[]
5. Done. You can see the generated links in the GET /template root, You can get the template as: html string, pdf buffer, pdf stream. Experiment and test with the playground link.
### get template html / pdf:
{{type}} = html_string | pdf_buffer | pdf_stream
POST /template/:name?type=html_string
```json
body: templateData
```
### mail send with template:
POST /mail
```typescript
body: {
mailOptions: Omit<Mail.Options, 'html'>;
template: { name: string; data: any };
}
```
```json
//example body
{
"mailOptions": {
"to": "test@gmail.com",
"subject": "test email"
},
"template": {
"name": "test_template",
"data": {
"title": "test title",
"description": "This is a test description",
"color": "#DEB887"
}
}
}
```
Demo: https://template.mytaskplan.me/template