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

https://github.com/baethon/mjml-api

Responsive email as a service
https://github.com/baethon/mjml-api

Last synced: 25 days ago
JSON representation

Responsive email as a service

Awesome Lists containing this project

README

        

# mjml-api [![Build Status](https://travis-ci.org/baethon/mjml-api.svg?branch=master)](https://travis-ci.org/baethon/mjml-api)[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

This project exposes [mjml](https://mjml.io) as an API service. It's meant* to be compatible with [MJML API ](https://mjml.io/api).

## Requirements

* Node >= 8
* Yarn

## Running

### From sources

```bash
yarn
yarn start
```

### Using heroku

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/baethon/mjml-api/tree/master)

### Using Docker image

```bash
docker run --rm -p 3000:8080 baethon/mjml-api
```

## Supported env variables

| Name | Alias | Default | Description |
| ----------- | ------ | --------- | -------------------------------------------------------------------------------------- |
| `NODE_PORT` | `PORT` | `3000` | Port to listen on |
| `NODE_HOST` | `HOST` | `0.0.0.0` | Host to listen on |
| `CORS` | | `*` | Set to `*` to enable CORS for all origins, or set a single origin `http://example.com` |

## API

This API aims to be combatible with MJML API.

Yet, there're few differences:

* **there's no client authorization** - make sure that API won't be publicly available
* `request_id` in errors will always be `NULL`
* `started_at` will return date in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601)

### Endpoints

#### POST /v1/render

Renders given MJML template.

##### Example request

```json
{
    "mjml": " Hello World "
}
```

##### Example response

```json
{
"html": "\n \n \n \n \n \n \n \n \n \n \n \n \n #outlook a { padding:0; }\n .ReadMsgBody { width:100%; }\n .ExternalClass { width:100%; }\n .ExternalClass * { line-height:100%; }\n body { margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%; }\n table, td { border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt; }\n img { border:0;height:auto;line-height:100%; outline:none;text-decoration:none;-ms-interpolation-mode:bicubic; }\n p { display:block;margin:13px 0; }\n \n \n \n @media only screen and (max-width:480px) {\n @-ms-viewport { width:320px; }\n @viewport { width:320px; }\n }\n \n \n \n \n \n \n \n @media only screen and (min-width:480px) {\n .mj-column-per-100 { width:100% !important; max-width: 100%; }\n }\n \n \n \n \n \n \n \n \n \n \n \n \n \n

\n \n \n \n \n \n
\n \n \n \n \n \n \n \n
\n \n \n \n \n \n \n

\n

\n \n \n \n \n \n \n \n \n \n \n
\n Hello World\n
\n \n \n \n \n \n \n
\n \n \n \n \n \n \n \n
\n \n \n \n \n \n
\n \n \n \n ",
"errors": [],
"mjml": " Hello World ",
"mjml_version": "4.2.1"
}
```

##### Example errors

```json
{
"request_id": null,
"started_at": "2018-12-27T14:01:30.732Z",
"message": "Invalid value [body > mjml]"
}
```

```json
{
"html": "\n \n \n \n \n \n \n \n \n \n \n \n \n #outlook a { padding:0; }\n .ReadMsgBody { width:100%; }\n .ExternalClass { width:100%; }\n .ExternalClass * { line-height:100%; }\n body { margin:0;padding:0;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%; }\n table, td { border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt; }\n img { border:0;height:auto;line-height:100%; outline:none;text-decoration:none;-ms-interpolation-mode:bicubic; }\n p { display:block;margin:13px 0; }\n \n \n \n @media only screen and (max-width:480px) {\n @-ms-viewport { width:320px; }\n @viewport { width:320px; }\n }\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ",
"errors": [
{
"line": 1,
"message": "Attribute width has invalid value: 100 for type Unit, only accepts (px) units and 1 value(s)",
"tagName": "mj-image",
"formattedMessage": "Line 1 of /home/radmen/Work/open-source/baethon/mjml-api (mj-image) — Attribute width has invalid value: 100 for type Unit, only accepts (px) units and 1 value(s)"
}
],
"mjml": "",
"mjml_version": "4.2.1"
}
```

## Testing

```bash
yarn test
```