Skip to content

A webservice to render HTML templates from API data

License

Notifications You must be signed in to change notification settings

veeso-dev/tokyo-draft

Repository files navigation

tokyo-draft

~ A webservice to render HTML templates from API data ~

Get started · Crates.io

Developed by @veeso

Current version: 0.1.2 (25/07/2023)

License-MIT Repo stars Ko-fi

Linux CI



About tokyo-draft

tokyo-draft is a Rust web service which renders HTML templates starting from incoming data from API. The API allows you to render any template you've pre-configured in the service configuration. The rendered template is then sent via a POST request to a configurable hook.


Get started

Run

First configure the environment file as you wish, then source .env and run tokyo-draft with

./tokyo-draft.sh start /var/run/tokyo-draft.pid

At this point tokyo-draft will be served on the specified port in the .env (or .env.override) file. (Default: 3011)

tokyo-draft API

Check

Check web service status:

GET /check

Response:

{
  "status": "ok"
}

Render

Render a template with provided data:

POST /render

payload:

{
  "template": "my-template",
  "data": {
    "key1": "value",
    "key2": 123,
  },
  "hookMetadata": {
    /* custom data to be passed to hook */
  }
}

Response (HTML):

(rendered template)

Errors

  • In case of missing keys or unknown template returns 400.

Hook API

It is possible to configure in the environment the key RENDER_HOOK to an URL which will receive the rendered template as parameter as follows:

{
  "body": "RENDERED TEMPLATE HTML SYNTAX BASE64 ENCODED",
  "metadata": {
    /* data passed as hookMetadata to /render */
  }
}

Support the developer

If you like tokyo-draft and you're grateful for the work I've done, please consider a little donation 🥳

You can make a donation with one of these platforms:

ko-fi PayPal


Contributing and issues

Contributions, bug reports, new features and questions are welcome! 😉 If you have any question or concern, or you want to suggest a new feature, or you want just want to improve pavao, feel free to open an issue or a PR.

Please follow our contributing guidelines


Changelog

View tokyo-draft's changelog HERE


License

tokyo-draft is licensed under the MIT license.

You can read the entire license HERE