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

https://github.com/veeso-dev/tokyo-draft

A webservice to render HTML templates from API data
https://github.com/veeso-dev/tokyo-draft

Last synced: about 1 year ago
JSON representation

A webservice to render HTML templates from API data

Awesome Lists containing this project

README

          

# 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

---

- [tokyo-draft](#tokyo-draft)
- [About tokyo-draft](#about-tokyo-draft)
- [Get started](#get-started)
- [Run](#run)
- [tokyo-draft API](#tokyo-draft-api)
- [Check](#check)
- [Render](#render)
- [Errors](#errors)
- [Hook API](#hook-api)
- [Support the developer](#support-the-developer)
- [Contributing and issues](#contributing-and-issues)
- [Changelog](#changelog)
- [License](#license)

---

## 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

```sh
./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:

```txt
GET /check
```

Response:

```json
{
"status": "ok"
}
```

### Render

Render a template with provided data:

```txt
POST /render
```

payload:

```json
{
"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:

```json
{
"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](https://img.shields.io/badge/Ko--fi-F16061?style=for-the-badge&logo=ko-fi&logoColor=white)](https://ko-fi.com/veeso)
[![PayPal](https://img.shields.io/badge/PayPal-00457C?style=for-the-badge&logo=paypal&logoColor=white)](https://www.paypal.me/chrisintin)

---

## 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](CONTRIBUTING.md)

---

## Changelog

View tokyo-draft's changelog [HERE](CHANGELOG.md)

---

## License

tokyo-draft is licensed under the MIT license.

You can read the entire license [HERE](LICENSE)