MJNML API

Welcome to MJNML - a minimal MJML parser API that converts MJML templates into responsive HTML email code.

What is MJNML?

MJNML is a simple Express API server that parses MJML (Mailjet Markup Language) templates and returns the HTML output. It provides a straightforward way to convert your MJML templates into responsive HTML email code through a REST API.

API Endpoints

POST /v1/render

Converts MJML markup to HTML.

Request:

{
  "mjml": "<mjml><mj-body><mj-section><mj-column><mj-text>Hello, World!</mj-text></mj-column></mj-section></mj-body></mjml>"
}

Response:

{
  "errors": [],
  "html": "\n[...]\n  ",
  "mjml": "Hello, World!",
  "mjml_version": "4.15.3"
}

GET /v1/health

Check if the API is running properly.

Response:

{ 
  "status": "OK", 
  "message": "mjnml MJML API is running" 
}

Example Usage

cURL

curl -X POST https://mjnml.private.coffee/v1/render \
  -H "Content-Type: application/json" \
  -d '{"mjml": "<mjml><mj-body><mj-section><mj-column><mj-text>Hello, World!</mj-text></mj-column></mj-section></mj-body></mjml>"}'

JavaScript

fetch('https://mjnml.private.coffee/v1/render', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    mjml: '<mjml><mj-body><mj-section><mj-column><mj-text>Hello, World!</mj-text></mj-column></mj-section></mj-body></mjml>'
  }),
})
.then(response => response.json())
.then(data => {
  console.log(data.html);
})
.catch((error) => {
  console.error('Error:', error);
});

Installation

If you want to set up your own instance of MJNML, you can install it from the repository or npm:

From Repository

git clone https://git.private.coffee/PrivateCoffee/mjnml.git
cd mjnml
npm install
npm start

From NPM

npx mjnml-api

Environment Variables

Use the PORT environment variable to specify the port the server should listen on.